我的假设是只要程序正在运行,finally 块总是会被执行。但是,在这个控制台应用程序中,finally 块似乎没有被执行。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
try
{
throw new Exception();
}
finally
{
Console.WriteLine("finally");
}
}
}
}
输出
注意:当抛出异常时,windows 询问我是否要结束应用程序,我说“是”。