class Class2 {
        static void Main(string[] args) {
            Exception exception = null;
            Thread thread = new Thread(() => SafeExecute(() => Test(0, 0), out exception));
            Console.WriteLine(Thread.CurrentThread.ManagedThreadId);
            thread.Start();

            thread.Join();

            Console.WriteLine(exception);

            Console.ReadLine();
        }

        private static void SafeExecute(Action test, out Exception exception) {
            Console.WriteLine(Thread.CurrentThread.ManagedThreadId);
            exception = null;

            try {
                test();
            }
            catch (Exception ex) {
                exception = ex;
            }
        }

        static void Test(int a, int b) {
            Console.WriteLine(Thread.CurrentThread.ManagedThreadId);
            throw new Exception();
        }

  

相关文章:

  • 2021-12-23
  • 2022-12-23
  • 2021-10-31
  • 2021-09-18
  • 2022-12-23
  • 2021-05-17
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-09-01
  • 2021-04-15
  • 2021-06-18
  • 2022-12-23
  • 2021-07-11
  • 2021-08-15
相关资源
相似解决方案