0

I created a VS2010 Windows service project. In it I invoke the method Microsoft.SqlServer.Management.Smo.Database.ExecuteWithResults(expression). In my scenario the expression contains invalid SQL, so the call fails with an exception as expected.

What's not expected is that the method is invoked within a try/finally block, but the finally block is NEVER executed:

try { database.ExecuteWithResults(invalid-sql) } 
finally { // code here is NOT executed }

However, if I change it to a try/catch/finally block, both the catch and finally code is invoked.

try { database.ExecuteWithResults(invalid-sql) } 
catch(Exception) { // code here is executed fine }
finally { // as is this code }

Am I missing something here? Shouldn't a finally block always get executed?

4

1 回答 1

0

在 Visual Studio 中,转到调试 | 异常...,您可以尝试检查不同级别的异常以“抛出”。在我只看到某些 3rd 方 win32 dll 发生这种情况之前,可以通过在该对话框中检查更多异常类型来捕获它们。

于 2012-05-15T01:44:53.897 回答