Exception handling allows you to design and code the normal case for your program separately from the code that handles exceptional situations.
An exception can be thrown in a try
block. Alternatively, an exception can be thrown in a function definition that does not include a try
block (or does not include a catch
block to catch that type of exception). In this case, an invocation of the function can be placed in a try
block.
An exception is caught in a catch
block.
A try
block may be followed by more than one catch
block. In this case, always list the catch
block for a more specific exception class before the catch
block for a more general exception class.
Do not overuse exceptions.