ADBRITE ads links
You are here: CodeIdol.com > Java > The Java Tutorial Fourth Edition: A Short Course on the Basics > Exceptions
The Java Tutorial Fourth Edition: A Short Course on the Basics
| Chapter 9. Exceptions
THE Java programming language uses exceptions to handle errors and other exceptional events. This chapter describes when and how to use exceptions.
...
|
|
| What Is an Exception?
The term exception is shorthand for the phrase "exceptional event."
Definition
An exception is an event, which occurs during the execution of a program, that disrupts the normal flow of the program's instruction...
|
|
| The Catch or Specify Requirement
Valid Java programming language code must honor the Catch or Specify Requirement. This means that code that might throw certain exceptions must be enclosed by either of the following:
A TRy statement that catches ...
|
|
| Catching and Handling Exceptions
This section describes how to use the three exception handler componentsthe try, catch, and finally blocksto write an exception handler. The last part of this section walks through an example and analyzes what occu...
|
|
| Specifying the Exceptions Thrown by a Method
The previous section showed how to write an exception handler for the writeList method in the ListOfNumbers class. Sometimes, it's appropriate for code to catch exceptions that can occur within it. In o...
|
|
| How to Throw Exceptions
Before you can catch an exception, some code somewhere must throw one. Any code can throw an exception: your code, code from a package written by someone else such as the packages that come with the Java platform, or the Ja...
|
|
| Unchecked ExceptionsThe Controversy
Because the Java programming language does not require methods to catch or to specify unchecked exceptions (RuntimeException, Error, and their subclasses), programmers may be tempted to write code that throws on...
|
|
| Advantages of Exceptions
Now that you know what exceptions are and how to use them, it's time to learn the advantages of using exceptions in your programs.
Advantage 1: Separating Error-Handling Code from "Regular" Code
Exceptions pr...
|
|
| Summary
A program can use exceptions to indicate that an error occurred. To throw an exception, use the throw statement and provide it with an exception objecta descendant of THRowableto provide information about the specific error that occurred. ...
|
|
| Questions and Exercises: Exceptions
Questions
1.Is the following code legal?
try {
} finally {
}
2.What exception types can be caught by the following handler?
catch (Exception e) {
}
What is wrong with using this type of exception...
|
|
You are here: CodeIdol.com > Java > The Java Tutorial Fourth Edition: A Short Course on the Basics > Exceptions
|
|
Related tags
Popular Categories
Unix books and guides
AJAX popular information
C# language guides
Windows books and cookbooks
.......
|
|