This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes confused on checked exceptions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "confused on checked exceptions" Watch "confused on checked exceptions" New topic
Author

confused on checked exceptions

Aaron Anders
Ranch Hand

Joined: Dec 30, 2002
Posts: 39
hello folks,

only case 1 will result in compile Error: "exception java.io.IOException is never thrown in body of corresponding try statement"
i am confused with the outcome: is the error above occurs only on checked exception? if so, how come both case 4,5 compiles successfully? because Exception and Throwable are supposed to be checked exception? or not?
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
It's because both Exception and Throwable have unchecked exceptions as subclasses. So where you sayWhen the compiler tries to figure out whether your catch clause can ever be executed, it comes up with the answer "yes" because it assumes that an unchecked RuntimeException can always be thrown, anywhere. And a RuntimeException or subclass would be caught by your Exception catch clause.
Same story for Throwable, except that that will catch Error as well.
- Peter
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: confused on checked exceptions
 
Similar Threads
Throwing own Exceptions
Checked exceptions
true or false?
Exception Question
Try - Catch Exception