Beruflich Dokumente
Kultur Dokumente
Throwing Exceptions
Catching Exceptions
Exceptions:
Can't be overlooked
Sent directly to an exception handlernot just
caller of failed method
Throw an exception object to signal an
exceptional condition
throw exceptionObject;
Example:
throw new IllegalArgumentException();
Purpose:
To throw an exception and transfer control to a
handler for this
exception type
NumberFormatException
IllegalArgumentException
NullPointerException
Example:
public void read(BufferedReader in) throws IOException
Purpose:
To indicate the checked exceptions that this method can throw
finally statement
used to handle an exception that is not caught by any
of the previous catch statements
finally block
used to handle an exception generated within a try
block
may be added immediately after the try block or after
the last catch block
when defined, it is guaranteed to execute, regardless
whether or not an exception is thrown
Purpose:
To ensure that the statements in the finally clause are
executed
whether or not the statements in the try block throw an
exception.