最后似乎并没有在使用F5在C#控制台应用程序来执行并没有、控制台、应用程序

2023-09-04 00:19:04 作者:不够洒脱

int i=0;
try{
    int j = 10/i;
}
catch(IOException e){}
finally{
    Console.WriteLine("In finally");
    Console.ReadLine();
}

finally块似乎并没有执行的时候在VS2008 pressing F5。 我用这code。在控制台应用程序。

The finally block does not seem to execute when pressing F5 in VS2008. I am using this code in Console Application.

推荐答案

Visual Studio调试器暂停执行,当你(零异常在这种情况下,除)得到一个未捕获的异常。在调试模式下的Visual Studio prefers中断执行,给你一个弹出框在错误的来源,而不是让应用程序崩溃。这是为了帮助你找到未被捕获的错误和解决这些问题。如果分离调试器这不会发生。

The Visual Studio debugger halts execution when you get an uncaught exception (in this case a divide by zero exception). In debug mode Visual Studio prefers to break execution and give you a popup box at the source of the error rather than letting the application crash. This is to help you find uncaught errors and fix them. This won't happen if you detach the debugger.

尝试从控制台运行它在释放模式不附加调试器,你会看到你的消息。

Try running it in release mode from the console without the debugger attached and you will see your message.