Link to home
Start Free TrialLog in
Avatar of lapucca
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.
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Hi lapucca;

Can you post your code please.
SOLUTION
Avatar of it_saige
it_saige
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>>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?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lapucca
lapucca

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
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Can you please post the actual code so we have a better idea of what is happening.
Avatar of lapucca

ASKER

Sorry, I didn't post the code because too much sensitive code that I would have to comment out.