这段代码为什么捕获不到异常呢?谁能给个解释,谢谢。

十年河东,十年河西,莫欺少年穷

学无止境,精益求精

这段代码我很迷惑,基础不好,只能求教各位博友了

如下:

    class Program
    {
        static void Main(string[] args)
        {
            Something();
            Console.ReadKey();
        }

        public static void Something()
        {
            try
            {
                 var result = SomethingWrongAsync();
            }
            catch (Exception)
            {
                Console.WriteLine("获取到了异常");
                throw;
            }
        }

        private static async Task SomethingWrongAsync()
        {
            await Task.Delay(100);
            throw new InvalidOperationException();
        }
    }
View Code

以上参考博客:https://www.cnblogs.com/manupstairs/p/12196909.html

@天才第一步,雀氏纸尿布的博客

原文地址:https://www.cnblogs.com/chenwolong/p/12197776.html