Good day all, I have this piece of exception handling code, from the Java OCA SE 8 certification book by Boyarski and Selikoff. I don't understand 1 detail and 1 variation of the code:
try {
throw new RuntimeException();
} catch (RuntimeException e) {
29: throw new RuntimeException();
} finally {
31: throw new Exception();
}
As is, the compiler issues this message:
error: unreported exception Exception; must be caught or declared to be thrown
throw new Exception();
On the other hand, if I delete line 31, it all goes well. So, my first question is: How come line 29, an uncaught exception (I think) is ok for the compiler ? Is it because the RuntimeException()
had already been caught before ?
The second question is: If I replace line 31 with
throw new RuntimeException();
It all goes well. But why ? I don't have any try/catch
inside the finally
block.
Any help to answer these two questions is welcome.
Thank you.