finally
block, in Java, will always be
executed. But, what if the try block stops by throwing an exception,
the exception is caught and an explicit return
is
called? ie. What's the result of the following code?
try { System.out.println(1); if (true) throw new Throwable(); System.out.println(2); } catch(Throwable e) { System.out.println(3); if (true) return; System.out.println(4); } finally { System.out.println(5); } System.out.println(6);
try { System.out.println(1); if (true) throw new Throwable(); System.out.println(2); } catch(Throwable e) { System.out.println(3); if (true) return (10); System.out.println(4); } finally { System.out.println(5); if (true) return (20); System.out.println(6); } System.out.println(7); return (30);