這是我的假設,只要程序運行,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");
}
}
}
}
輸出
注:當異常被拋出,窗戶askmed我,如果我想結束appliation,我說: '是的。'
點擊'no'看看會發生什麼 –
來看,它的命令行,而不是你的IDE – KevinDTimm
內它看起來非常奇怪。 '最後'應該在StackTrace後寫完。 –