E. When considering fragments II, III and IV, of those that will compile, adding a try/catch block around line 4 will cause compilation to fail.
John Lerry wrote:I had indicated an error in compile time because I had noticed in the catch block that the exception was rethrows but was not declared in the method signature.
This however is not correct and the solution is "-ic mc mf of".
Is it not correct what I said?
John Lerry wrote:If it were not for the code snippet IV I would have considered true because if you want to declare AND handle an exception (checked) need to rethrow the exception in the catch block, otherwise there will be an error in compilation.
My reasoning is this correct?
John Lerry wrote:Simply put, when I have to declare AND handle the exception? and when I have to declare OR manage it?
John Lerry wrote:are ALL correct?
If you throw a checked exception from a catch clause, you must also declare that exception! In other words, you must handle AND declare, as opposed to handle OR declare.
John Lerry wrote:because was re-throws a checked exception but the rule "handle OR declared" is violated because in this case is handle AND declare.
is it correct?
John Lerry wrote:My doubt is due to this phrase in the book (K&B7):
If you throw a checked exception from a catch clause, you must also declare that exception! In other words, you must handle AND declare, as opposed to handle OR declare.
John Lerry wrote:because the exception (the same) is re-throws in the catch block but not declared (in the method signature).
Is it correct?
John Lerry wrote:I have another question. I have noticed that there are, in the exam, questions on some exceptions throw by the JVM and some throw by the developer. For this type of questions I have to try to remember the table at the end of this chapter 6 but I would have some doubts about the other exceptions.
To determine which exceptions are unchecked should I try to learn the most exceptions subclasses of RuntimeException? In few words, is it a work of memory?
Consider Paul's rocket mass heater. |