![]() |
The Simons
|
#include <Exception.h>
Inheritance diagram for Exception:
Whenever a runtime failure is detected, programs will create an instance of Exception (or of one of its more specfic subclasses) and raise this using throw()
. By default, raising an Exception will terminate the program with an Abort
signal. However, programs may choose to handle Exceptions using catch()
to trap specific kinds of Exception. A fault-tolerant program should be placed inside a try{...}
block, followed by one or more catch(ExceptionID ex){...}
blocks, in which the specific type of the ExceptionID variable determines which class of Exceptions will be caught by that handler. Exception provides access to the failed object() and the error message() and will report() this message on the standard error stream, giving a backtrace if several Exceptions were chained together. This may be desired when a caught Exception must necessarily throw another one inside the catch()
handler.
The above example raises a NoElements exception, which is caught by the first catch()
handler. The second handler is there to catch a NullPointer exception (but none is raised). This allows different types of Exception to be handled specially, or not at all. Handlers will catch Exceptions of their own type, or of more specific types. Catching a most general ExceptionID at the top level is the normal way to report system failure.
Public Member Functions | |
Exception () | |
Construct a default Exception. | |
virtual | ~Exception () |
Release an unused Exception. | |
Exception (ObjectID, StringID) | |
Construct an Exception reporting failure in an Object. | |
virtual ObjectID | clone () const |
Clone a copy of this Exception. | |
ObjectID | object () const |
Access the failed Object. | |
StringID | message () const |
Access the error message String. | |
Void | causedBy (ExceptionID) |
Establish the cause of this Exception. | |
ExceptionID | cause () const |
Access the cause of this Exception. | |
Void | report () const |
Report an Exception on the standard error stream. | |
Void | reportOn (OutputID) const |
Report an Exception on an existing Output stream. | |
Protected Member Functions | |
Exception (const Exception &) | |
Copy another Exception. | |
Protected Attributes | |
ObjectID | failedObject |
The Object which failed. | |
StringID | errorMessage |
An error message String. | |
ExceptionID | priorException |
An Exception that caused this one. |
|
Copy another Exception. Required by C++ to ensure that copying an Exception faithfully copies the parent Object. Creates a shallow copy of the argument Exception, which shares its failed object, error message and any prior Exception with this Exception.
|
|
Construct a default Exception. Initialises the failedObject to null; and the errorMessage to "Default exception".
|
|
Release an unused Exception.
|
|
Construct an Exception reporting failure in an Object.
|
|
Access the cause of this Exception.
|
|
Establish the cause of this Exception. If this Exception is raised inside the catch {} block handling a prior Exception, set the prior Exception as the cause of this one. Doing this will allow report() to print an informative backtrace of chained Exceptions.
|
|
Clone a copy of this Exception.
Reimplemented from Object. Reimplemented in DeviceBusy, NoElements, NoResponse, NotFound, NullPointer, OutOfRange, ReadFailure, TypeFailure, Undefined, and WriteFailure. |
|
Access the error message String.
|
|
Access the failed Object.
|
|
Report an Exception on the standard error stream. The default way to report an Exception. Prints a message "ERROR :" followed by the name of the type of the failed object and the text of the error message. If the failed object is null, this indicates a failure in the top-level System. If this Exception was caused by a prior Exception, prints a complete backtrace of the chain of Exceptions on the standard error stream. |
|
Report an Exception on an existing Output stream. The normal way for a CGI program to report an Exception on the standard output stream, which must have been opened. Also used to print the complete backtrace of a chain of nested Exceptions. Prints a message "ERROR :" followed by the name of the type of the failed object and the text of the error message. If this Exception was caused by a prior Exception, prints the message: "Caused by " and then calls this method recursively to report the prior Exception.
|
|
An error message String.
|
|
The Object which failed.
|
|
An Exception that caused this one.
|