lapucca
asked on
C# return doesn't hit the Finally block
Hi, I'm using VS2013, c# and asp.net webform
In a couple of my methods, I use "return" in the middle of the code when certain conditions are met. To my surprise, my finally block code is not triggered when return is hit and it just leaves the method. Is there a way to make it go to finally block before leaving the method/
Thank you.
In a couple of my methods, I use "return" in the middle of the code when certain conditions are met. To my surprise, my finally block code is not triggered when return is hit and it just leaves the method. Is there a way to make it go to finally block before leaving the method/
Thank you.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>>my finally block code is not triggered when return is hit and it just leaves the method.
How do you test that - or is that an assumption based on something else?
How do you test that - or is that an assumption based on something else?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Okay, I stepped through in Debug mode after a return statement the finally block wasn't hit. But now, I'm thinking is it because the return statement was outside of the try block? If the return is hit before try, catch and finally blocks then the finally doesn't get hit at all, right?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Can you please post the actual code so we have a better idea of what is happening.
ASKER
Sorry, I didn't post the code because too much sensitive code that I would have to comment out.
Can you post your code please.