Hi, Please tell me the purpose of return in catch or finally block. what will happen if we don't place return.
thanks in advace Vidya
bill bozeman
Ranch Hand
Joined: Jun 30, 2000
Posts: 1070
posted
0
You don't have to put a return statement in a catch or finally block, and I would only do so if I wanted the rest of the method to stop after the finally statement. Generally it will work like this: With no return statement: If an error arises in try block, execution moves to coorsponding catch block, then to the finally block, then to rest of the method. With a return statement in the catch or finally block: If an error arises in try block, execution moves to coorsponding catch blcok, then to the finally block, then out of the method since you returned a value. So I would use a return statement if for one exception you wanted the rest of the method to continue after the finally block, but say for another exception you wanted the method to stop executing. The reason I say it this way is because if you wanted the method to not doing anything else after the finally block, you could just wrap the whole method in the try block, but that doesn't work if you want different exceptions to behave differently. Does this make sense? I'll include code if this is confusing.
Ajith Kallambella
Sheriff
Joined: Mar 17, 2000
Posts: 5782
posted
0
Checkout one of my very old post on this topic Ajith
Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
bill bozeman
Ranch Hand
Joined: Jun 30, 2000
Posts: 1070
posted
0
Thanks Ajith, that explains it better than I was able to do.
sri vidya
Greenhorn
Joined: Oct 10, 2000
Posts: 5
posted
0
Thankyou Ajith and Bill bozeman for your explanation. Vidya.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.