SQL SMO异常导致最后一个块被跳过?

时间:2012-05-02 06:31:48

标签: sql try-catch smo finally

我创建了一个VS2010 Windows服务项目。在其中我调用方法Microsoft.SqlServer.Management.Smo.Database.ExecuteWithResults(expression)。在我的方案中,表达式包含无效的SQL,因此调用失败并出现预期的异常。

不期望的是在try / finally块中调用该方法,但是finally块永远不会被执行:

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

但是,如果我将其更改为try / catch / finally块,则会调用catch和finally代码。

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

我在这里遗漏了什么吗?不应该总是执行finally块吗?

1 个答案:

答案 0 :(得分:0)

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

相关问题