[Return to Bookshelf] [Contents] [Previous Section] [Next Section] [Index] [Help]


5.2.1 Declaring and Initializing an Exception Object

An exception object is an opaque type that should only be manipulated by the exception package functions. The actual definition of the type may differ from one implementation to another.

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.

An exception is declared as a variable of type EXCEPTION. In general, you should declare the type as static or extern. For example:

static EXCEPTION an_error;

Because an exception object may require dynamic initialization on some platforms, the DECthreads exception package requires a run-time initialization call in addition to the declaration. The initialization function is a macro named EXCEPTION_INIT. The name of the exception is passed as a parameter.

Following is an example of declaring and initializing an exception object:

EXCEPTION parity_error;         /* Declare it */
EXCEPTION_INIT (parity_error);  /* Initialize it */