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?

Dan
  • 1,215
  • 1
  • 10
  • 22

1 Answers1

0

In Visual Studio, go to Debug | Exceptions..., you can try checking different level exceptions to be "thrown". Before I only saw this happening to some 3rd party win32 dlls, and they could be caught by checking more exception types in that dialog.

detale
  • 12,482
  • 4
  • 41
  • 42