OK, I'm randomly going over Sierra/Bates in preparation for the showdown in about two weeks....
I understand that Checked Exceptions are Checked by Compiler to see if they are Handled or Declared. But I cannot understand the following from Sierra/Bates, Chapter 5:
When an object of a subtype of Exception is thrown, it must be handled or declared. These objects are called checked exceptions, and include all exceptions except those that are subtypes of RuntimeException, which are unchecked exceptions. Be ready to spot methods that don’t follow the “handle or declare” rule, such as
You need to recognize that this code won’t compile. If you try, you’ll get
MyException.java:3: unreported exception MyException; must be caught or declared to be thrown doStuff();
Notice that someMethod() fails to either handle or declare the exception that can be thrown by doStuff().
This doesn't make sense. I thought the checked exception was declared with
catch clause in doStuff throws an exception, but who on Earth is going to catch it? someMethod, that's who! However, someMethod fails declare that it throws MyException, nor does it place the method call doStuff() in a try/catch block