OSF DCE Application Development Guide--Core Components
OSF DCE Application Development Guide—Core Components
9.3.5 Defining Epilogue Actions for a Block
A FINALLY mechanism is provided so that multithreaded programs can restore
invariants as certain scopes are unwound; for example, restoring shared data to a correct
state and releasing locks. This is often the ideal way to define, in one place, the cleanup
activities for normal or abnormal exit from a block that has changed some invariant.
Following is an example of specifying an invariant action whether or not there is an
error:
lock_tape_drive (t);
TRY
TRY
read_tape ();
CATCH (parity_error)
printf ("Oops, parity error, program terminating\n");
printf ("Try cleaning the heads!\n");
RERAISE;
ENDTRY
/* Control gets here only if no exception is raised */
/* ... Now we can use the data off the tape */
FINALLY
/* Control gets here normally, or if any exception is */
raised unlock_tape_drive (t);
ENDTRY
9.3.6 Importing a System-Defined Error Status into the Program as an
Exception
Most systems define error messages by integer-sized status values. Each status value
corresponds to some error message text that should be expressed in the user’s own
language. The capability to import a status value as an exception permits the DCE
Threads exception-returning interface to raise or handle system-defined errors as well as
programmer-defined exceptions.
An example of importing an error status into an exception is as follows:
exc_set_status (&parity_error, EPARITY);
The parity_error exception can then be raised and handled like any other exception.
9− 6 Tandem Computers Incorporated 124245