Example #1
0
        public void TestOrder()
        {
            Action <string> show  = msg => Console.WriteLine($"show:{msg}\n");
            Action          begin = () => Console.WriteLine("begin\n");
            Action          end   = () => Console.WriteLine("end\n");
            var             test  = new TryCatch(show);

            test.Invoke(() => Console.WriteLine("test\n"));
            Console.WriteLine(test.Invoke("default", () => "test"));
            Console.WriteLine(test.Invoke("default", () => { Console.WriteLine("1 \n"); return("test"); }));
            Console.WriteLine(test.Invoke("default", WriteTest));
        }
Example #2
0
 private static void InvokeTryCatch(string method, TryCatch action)
 {
     try
     {
         action?.Invoke();
     }
     catch (Exception exp)
     {
         if (VolumeHelper.ThrowException)
         {
             throw;
         }
         else
         {
             string msg = string.Format("在执行函数 VolumeHelper.{0}(*) 时发生异常: {1} (若要查看完整异常 请设置 VolumeHelper.ThrowException=true;)", method, exp.Message);
             VolumeHelper.RecordException(msg);
         }
     }
 }