|
|
Start of Tutorial > Start of Trail |
Search
Feedback Form |
It's an unfortunate fact we try hard to avoid: Errors occur in software programs. However, the proper handling of errors greatly improves a program’s readability, reliability and maintainability. The Java programming language uses exceptions for error handling. This chapter describes when and how to handle errors using exceptions.
Note: This chapter has been updated to reflect features and conventions of the latest release, JDK 5.0, but it is not yet final. Weve published this preliminary version so you can get the most current information now.
What Is an Exception?
- The Java programming language uses exceptions to provide error-handling capabilities for its programs. An exception is an event that occurs during the execution of a program that disrupts the normal flow of instructions.
The Catch or Specify Requirement
- This section covers how to catch and handle exceptions. Included in our discussion are; the try, catch, and finally blocks, as well as chained exceptions and logging.
How to Throw Exceptions
- This section covers the throw statment and the Throwable class and its sublclasses.
Runtime Exceptions—The Controversy
- Since the Java programming language does not require methods to catch or to specify runtime exceptions or errors, programmers can be tempted to write code that throws only runtime exceptions. In this section we explain why you shouldn't be tempted.
Advantages of Exceptions
- The use of exceptions to manage errors has some advantages over traditional error-management techniques. You'll learn more in this section.
Summary
Questions and Exercises: Exceptions
|
|
Start of Tutorial > Start of Trail |
Search
Feedback Form |
Copyright 1995-2005 Sun Microsystems, Inc. All rights reserved.