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?