posted 23 years ago
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.