Java's Error ClassesSo far, you've had a look at the exception classes you can handle in your own programs. Java also defines a set of error classes that are really little more than special types of exceptions. These error classes are subclasses of Error, which, like Exception, is a subclass of Throwable. Java's error classes represent serious errors, such as running out of memory or encountering an internal error in the virtual machine. Just as with unchecked exceptions, you are not required to handle the errors that might be thrown by a method. The rationale is quite different in this case however. Remember that unchecked exceptions should never occur in a correctly written program. Errors represented by the Error subclasses, however, might very well occur in a correct program, but they are so severe that there is no assumption by the compiler that you can handle them. After all, if you totally run out of memory or overflow the stack, it's likely too late to do anything about it. Table 4.3 gives some examples of the error classes. All but AWTError are defined in java.lang. Table 4.3. Examples of the Java Error Classes
|