Subsections
- Exceptions are caught by enclosing code in try blocks.
- The body of try is executed until an exception is thrown or it finishes successfully.
- If an exception is thrown, each catch clause is examined in turn, from first to last, to see whether the exception object is assignable tto the type declared with the catch.
- When an assignable catch is found, its code block is executed. No other catch clause will be executed.
- Any number of catch clauses can be associated with a try, as long as each clause catches a different type of exception.
- If a finally clause is present in the try block, the code is executed after all other processing in the try is complete. This happens no matterhow the try clause completed - normally, through an exception, or through a return or break.
- A mechanism for executing a section of code whether or not an exception is thrown.
- Usually used to clean up internal state or to release non-object resources, such as open files stored in local variables.
- Can also be used to cleanup for break, continue, and return.
- No way to leave a try block without executing its finally clause.
- A finally clause is always entered with a reason; that reason is remembered when the finally clause exits.
Next: When to use exceptions
Up: Exceptions
Previous: The throws clause
  Contents
|
|