J2EEOnline
GofPatterns OOPortal
prev next prev next
  Course navigation
 
Lesson 8
Objective
Java Exception Subclasses
Identify Java's Exception subclasses/ state difference between checked/unchecked exception.
   
Java defines a class called Exception, which represents generic unexpected events.
Subclasses define specific unexpected events.
There are two general categories of exceptions: checked and unchecked. Unchecked exceptions descend from RuntimeException and Error, which are subclasses of Exception.
You should leave unchecked exceptions to Java.
That is, you should always throw checked exceptions, never subclasses of RuntimeException or Error. You can look through the APIs for the different types of checked and unchecked exceptions that Java defines.
The difference between a checked and unchecked exception is that you do not have to wrap the call to a method that might throw an unchecked exception in a try/catch block, while you must do so for a checked exception. But unchecked exceptions will halt your thread just the same as checked exceptions if you don't catch them.
Here is a listing of some of the more common exceptions in Java and where they might occur:
  Course navigation