Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finally AND Return 1

Status
Not open for further replies.

baddos

MIS
Dec 3, 2002
2,360
US
Does anyone know if a Return will still process a finally statement?

If I am in a Try/Catch/Finally Block within a function, will the Finally part get executed if in the Try or Catch part I put a Return statement?

All the books and documentions aren't very clear of this. I have read that a Finally statement will always run, but then it's contricted by a Return statement that always exits the function and stops processing it.
 
A finally block always executes, even if you return a value.
 
So... Given this code, if strText will always be = "Finally"?

Try
If 1 = 1 Then
Return "1 is equal to 1"
End If
Catch ex As Exception
Return "Bleh"
Finally
strText = "Finally"
End Try
 
Why not step through the code to see what happens?

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
Yep... I tested it and it works. Finally will run before Return.

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top