The JavaTM Tutorial
Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail > Start of Lesson Search
Feedback Form

Trail: Essential Java Classes
Lesson: Handling Errors with Exceptions

Summary

A program can use exceptions to indicate that an error occurred. To throw an exception, you use the throw statement and provide it with an exception object\227a descendant of Throwable—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, and finally statements. The try statement identifies a block of code in which an exception can occur. The catch statement identifies a block of code, known as an exception handler, that can handle a particular type of exception. The finally statement identifies a block of code that cleans up regardless of whether an exception occurred within the try block. A try statement must be accompanied by at least one catch statement or a finally statement and may have multiple catch statements.

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.


Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail > Start of Lesson Search
Feedback Form

Copyright 1995-2005 Sun Microsystems, Inc. All rights reserved.