Java s Error Classes

   

Java's Error Classes

So 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
Exception Caused By
AbstractMethodError Attempting to call an abstract method
AWTError A problem in an AWT user interface method
ClassFormatError An attempt to load a class file that is malformed
InstantiationError An attempt to instantiate an abstract class or an interface
InternalError A problem in the virtual machine
NoClassDefFoundError An inability to locate and load a class file that was present when the class that depends on it was compiled
OutOfMemoryError Having insufficient memory to create an object
StackOverflowError Recursion so deep that it overflows the stack
VirtualMachineError A flaw in the virtual machine or its inability to allocate the resources it needs to operate
   


Special Edition Using Java 2 Standard Edition
Special Edition Using Java 2, Standard Edition (Special Edition Using...)
ISBN: 0789724685
EAN: 2147483647
Year: 1999
Pages: 353

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net