【问题标题】:SQL SMO exception causes finally block to be skipped?SQL SMO 异常导致 finally 块被跳过?
【发布时间】:2012-05-11 15:13:11
【问题描述】:

我创建了一个 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 块不应该总是被执行吗?

【问题讨论】:

    标签: sql try-catch smo finally


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2013-06-03
      • 1970-01-01
      • 2011-01-31
      • 2014-01-08
      • 2012-07-11
      • 2022-01-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多