Click to edit Master text styles
Second level
Third level
Fourth level
Fifth level
‹#›
1
3
Show BadArry.java here
Make the point that they are not compile time errors or logic errors.
4
Example from text:  BadArray.java
5
Note that Exception and Errors are classes derived from Throwable which is derived from Object.
Programmers should not attempt to handle classes derived from Error. are for exceptions that are thrown when critical errors occur. (i.e.)  an internal error in the Java Virtual Machine, or running out of memory.  Applications should not try to handle these errors because they are the result of a serious condition.
The should attempt to handle instances of classes derived from Exception. 
6
(the curly braces are required).
A try block is:
one or more statements that are executed, and
can potentially throw an exception.
The application will not halt if the try block throws an exception.
After the try block, a catch clause appears
A catch clause begins with the key word catch:
catch (ExceptionType ParameterName)
ExceptionType is the name of an exception class and
ParameterName is a variable name which will reference the exception object if the code in the try block throws an exception.
The code that immediately follows the catch clause is known as a catch block (the curly braces are required).
The code in the catch block is executed if the try block throws an exception.
7
Discuss again what happens if there isn’t a catch clause that will deal with the particular exception.
Show ReadFromFile.java
8
This is the same message that is displayed when the exception is not handled and the application halts.
ParseIntError.java
10
Show it by altering BadArray.java
Can use Exception e  only to determine what the actual exception was.
11
Text examples include:  SalesReport.java  and SalesReport2.java
The catch clauses must be listed from most specific to most general.
12
There can be many polymorphic catch clauses.
13
This will be caught by the compiler because NumberFormatException is derived from IllegalArgumentException (see page 765)
Re-ordering the catch blocks will make the code compile
16
StackTrace.java
All exception objcts have a printStackTrace method inherited from the Throwable class that can be used to print a stack trace.
18
20
The thrwo statement causes and exception to be thrown.
The throws clause informs the compiler that a method throws one or more exceptions
22
Throws statement in header is only necessary if exception handler not present.
27
The following rules apply
The @exception tag in a method’s documentation comment must appear after the general description of the method.
The description can span several lines. It ends at the end of the documentation comment (the */ symbol) or at the beginning of another tag.