Dear Peers & Mentors,
First off my questions come from my study of "A Programmer's Guide to
Java Certification" by Khalid and Rolf, second half of chapter five, around pages 154 to 158.
I am having trouble understanding what checked versus unchecked exceptions mean. I am tempted to ask what I will need to know for the exam, but I would REALLY like to get a better understanding than the bare minimum of this concept and not get just the basics. Without further postponement, let us move on.
First, all exceptions come from java.lang.Throwable, specifically Error and Exception. Now, RuntimeExceptions are derived from the class Exception. Now, according to the book Error, RuntimeException and all related subclasses are unchecked exceptions. Any other exception is classified as a checked exception. Later, on page 155 they state that new exceptions are created by extending the Exception class or its subclasses thereby making them checked exceptions.
But wait�doesn�t RuntimeException come from Exception and it is unchecked? How can this be? So�I could extend RuntimeException and since the subclasses of RuntimeException are unchecked my new exception would be unchecked. Hmm, but we just said that extending Exception or its subclasses thereby creates checked exceptions.
As you can tell, I�m running circles and I hope someone has an EASY way for me to tell checked and uchecked exceptions apart. I just want to be able to identify them easily and have a better working knowledge of what to do with them.
Finally, it is my understanding that checked exceptions must be dealt with via a try-catch-finally structure or the method containing the checked exception creation must declare that it throws that exception(or a superclass of that exception). Is THIS correct?
Thanks everybody!
Sincerely,
Jason