try – catch – finally

 

  A try can appear with no catch, but with just a finally.  i.e.

 

  The scope of catch’s variable is confined to the catch block itself. 

 

  The most general exception goes LAST in a catch block.

The compiler won't allow you to mistakenly put the most general exception first.

 

  The EXCEPTION e part of the catch statement must go in parens.  ie. catch ( IOEXCEPTION e ) {  }

 

finally

 

  finally is (almost) always executed, even if there’s no exception thrown. (see next item below) 

 

  The only exception to the above rule is when System.exit(...); is called above the finally. 

 

  finally is executed just before any return statement appearing above it.  Then the return.  So any return code on the return isn’t sent out until after the finally.

 

  finally is executed even if an outside method called by the try block throws an unknown or uncaught exception.