How try and catch Work
Here is how try and catch work:
- When an exception is thrown (by any statement in the
try{} block)
the catch{} blocks are examined one-by-one starting starting with
the first.
- Only one
catch{} block may be picked.
- If no
catch{} block matches the exception, none is picked,
and execution leaves this method (just as if there were no try{} block.)
- The first
catch{} block to match the type of exception thrown
is the one that gets control.
- The most specific exception types should appear first in the structure,
followed by the more general exception types.
- The statements in the choosen
catch{} block execute sequentially.
After the last statement executes, control goes to the first statement
that follows the try/catch structure.
- Control does not return to the
try block.
|