In this chapter you have learned what exceptions are and how to deal with them in your programs. You should make sure that you consider exception handling as an integral part of developing your Java programs. The robustness of your program code depends on how effectively you deal with the exceptions that can be thrown within it.
The important concepts you have explored in this chapter are:
Exceptions identify errors that arise in your program.
Exceptions are objects of subclasses of the Throwable class.
Java includes a set of standard exceptions that may be thrown automatically, as a result of errors in your code, or may be thrown by methods in the standard classes in Java.
If a method throws exceptions that aren't caught, and aren't represented by subclasses of the Error class or by subclasses of the RuntimeException class, then you must identify the exception classes in a throws clause in the method definition.
If you want to handle an exception in a method, you must place the code that may generate the exception in a try block. A method may have several try blocks.
Exception handling code is placed in a catch block that immediately follows the try block that contains the code that can throw the exception. A try block can have multiple catch blocks that each deals with a different type of exception.
A finally block is used to contain code that must be executed after the execution of a try block, regardless of how the try block execution ends. A finally block will always ...