Your method is declared to return an int, so all possible exit points from the method have to return an int. You do not need to have a finally clause, but if you don't have one, the last statement of the method needs to return an int. I don't think it's good style to use a return statement in the finally clause, because it will silently override the return statements in your exception-handling code. [ September 04, 2002: Message edited by: Ron Newman ]
You need the finally block because the method testX is declared to return an int. Each of the catch blocks returns an int and so does the finally block, but the actual body of the method itself doesn't. So, if you compile it without the finally block the compiler will complain about the method signature.
posted 17 years ago
Run that with an argument of 1, 2, or 3, and you may be very surprised by the return value printed out!