OSF DCE Application Development Guide--Core Components
OSF DCE Application Development Guide—Core Components
9.3 Operations on Exceptions
An exception is an object that describes an error condition. Operations on exception
objects allow errors to be reported and handled. If an exception is handled properly, the
program can recover from errors. For example, if an exception is raised from a parity
error while reading a tape, the recovery action may be to retry 100 times before giving
up.
The DCE Threads exception-returning interface allows you to perform the following
operations on exceptions:
• Declare and initialize an exception object
• Raise an exception
• Define a region of code over which exceptions are caught
• Catch a particular exception or all exceptions
• Define epilogue actions for a block
• Import a system-defined error status into the program as an exception
These operations are discussed in the following subsections.
9.3.1 Declaring and Initializing an Exception Object
Declaring and initializing an exception object documents that a program reports or
handles a particular error. Having the error expressed as an exception object provides
future extensibility as well as portability. Following is an example of declaring and
initializing an exception object:
EXCEPTION parity_error; /* Declare it */
EXCEPTION_INIT (parity_error); /* Initialize it */
9.3.2 Raising an Exception
Raising an exception reports an error, not by returning a value, but by propagating an
exception. Propagation involves searching all active scopes for code written to handle
the error or code written to perform scope-completion actions in case of any error, and
then causing that code to execute. If a scope does not define a handler or epilogue block,
then the scope is simply torn down as the exception propagates through the stack. This
is sometimes referred to as unwinding the stack. DCE Threads exceptions are
terminating; there is no option to make execution resume at the point of the error.
(Execution resumes at the point where the exception was caught.)
9− 4 Tandem Computers Incorporated 124245