【发布时间】:2012-12-25 03:00:02
【问题描述】:
我的假设是只要程序运行,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 询问我是否要结束应用程序,我说“是”。
【问题讨论】:
-
点击
no看看会发生什么 -
从命令行而不是在您的 IDE 中运行它
-
看起来很奇怪。 'finally' 应该写在 StackTrace 之后。
-
没有catch,异常未处理,应用退出
-
Ilya - 没有选择拒绝。另一种选择是“调试”。 Kevin - 它从命令行运行,而不是 IDE。
标签: c# .net exception try-catch try-finally