Try Catch Finally - will it execute?

  • Thread starter Thread starter Mark
  • Start date Start date
M

Mark

I know that the whole point of the 'Finally' statement is to always execute,
but will it execute in the following statement:

dbConnection.Open
Try
rowsAffected = dbCommand.ExecuteNonQuery
Catch
Response.Redirect("../error.aspx?Error=2")
Finally
dbConnection.Close
End Try


or will the response.Redirect in the catch statement not allow it to
execute?
 
Mark said:
I know that the whole point of the 'Finally' statement is to always execute,
but will it execute in the following statement:

dbConnection.Open
Try
rowsAffected = dbCommand.ExecuteNonQuery
Catch
Response.Redirect("../error.aspx?Error=2")
Finally
dbConnection.Close
End Try


or will the response.Redirect in the catch statement not allow it to
execute?

Response.Redirect is implemented by throwing a ThreadAbortException. It's a
normal exception so your Finally block should execute. Easy to test though.

David
 
The best way to see whats going on in your code is to
click to left of code in section you want to examine that
puts a break point. click F5 to start. do something in
your program like a button click or whatever makes your
program execute that code. program stops at that
breakpoint then push F8 to stepinto your program. You
might want to minimize your form so you can see your code
execute. hope it helps
 
Back
Top