Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
A program can use exceptions to indicate that an error occurred. To throw an exception, you use thethrow
statement and provide it with an exception object a descendant ofThrowable
to provide information about the specific error that occurred. A method that throws an uncaught, checked exception must include a throws clause in its declaration.A program can catch exceptions by using a combination of the
try
,catch
, andfinally
blocks. Thetry
block identifies a block of code in which an exception can occur. Thecatch
block identifies a block of code, known as an exception handler, that can handle a particular type of exception. Thefinally
block identifies a block of code that cleans up regardless of whether an exception occurred within thetry
block. Thetry
statement must should contain at least onecatch
block or afinally
block and may have multiplecatch
blocks.The class of the exception object indicates the type of the exception thrown. The exception object can contain further information about the error, including an error message. With the chained exception feature added in 1.4, an exception can point to the exception that caused it, which can in turn point to the exception that caused it, and so on.
Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
Copyright 1995-2005 Sun Microsystems, Inc. All rights reserved.