img
System.out.println("procC's finally");
}
}
public static void main(String args[]) {
try {
procA();
} catch (Exception e) {
System.out.println("Exception caught");
}
procB();
procC();
}
}
In this example, procA( ) prematurely breaks out of the try by throwing an exception.
The finally clause is executed on the way out. procB( )'s try statement is exited via a return
statement. The finally clause is executed before procB( ) returns. In procC( ), the try statement
executes normally, without error. However, the finally block is still executed.
REMEMBER  If a finally block is associated with a try, the finally block will be executed upon
EMEMBER
conclusion of the try.
Here is the output generated by the preceding program:
inside procA
procA's finally
Exception caught
inside procB
procB's finally
inside procC
procC's finally
Java's Built-in Exceptions
Inside the standard package java.lang, Java defines several exception classes. A few have
been used by the preceding examples. The most general of these exceptions are subclasses
of the standard type RuntimeException. As previously explained, these exceptions need
not be included in any method's throws list. In the language of Java, these are called
unchecked exceptions because the compiler does not check to see if a method handles or
throws these exceptions. The unchecked exceptions defined in java.lang are listed in
Table 10-1. Table 10-2 lists those exceptions defined by java.lang that must be included
in a method's throws list if that method can generate one of these exceptions and does
not handle it itself. These are called checked exceptions. Java defines several other types
of exceptions that relate to its various class libraries.
Search WWH :
Custom Search
Previous Page
Java SE 6 Topic Index
Next Page
Java SE 6 Bookmarks
Home