Exceptions come in two flavors: checked and unchecked. : try catch « Statements « SCJP






Checked exceptions include all subtypes of Exception, excluding classes that extend RuntimeException.

Checked exceptions are subject to the handle or declare rule; 

Any method that might throw a checked exception must either declare the exception using throws, 
or handle the exception with an appropriate try/catch.

Subtypes of Error or RuntimeException are unchecked

If you use an optional finally block, it will always be invoked

finally block will not be invoked if the JVM shuts down. 

Code in the finally block could itself raise an exception or issue a System.exit().

Uncaught exceptions propagate back through the call stack.

You can create your own exceptions, normally by extending Exception or one of its subtypes. 

All catch blocks must be ordered from most specific to most general. 

The Hierarchy of Throwable Things

java.lang.Object
   +- java.lang.Throwable
           + java.lang.Error
           |       +-various errors
           |
           + java.lang.Exception
                   + java.lang.RuntimeException
                   |       +- various unchecked exceptions
                   +- various checked exceptions

Subclasses of Error class signals errors that are usually fatal and are not caught by catch statements. 

The general form of try...catch is as follows

  try {
    // guarded region
  }
  catch(MyFirstException) {
    // handles this exception
  }
  catch(MySecondException) {
    // handles this exception
  }
  finally {
    // release any resource
  }








5.9.try catch
5.9.1.Exceptions come in two flavors: checked and unchecked.
5.9.2.A handler for a supertype of the exception.
5.9.3.Multiple catch Clauses and Work with finally
5.9.4.A try block may contain code that throws different exception types.
5.9.5.Rethrow exception, no try...catch