OSF DCE Application Development Guide--Core Components
OSF DCE Application Development Guide—Core Components
ENDTRY
A try_block or a handler_block is a sequence of statements, the first of which may be
declarations, as in a normal block. If an exception is raised in the try_block, the catch
clauses are evaluated in order to see if any one matches the current exception.
The CATCH or CATCH_ALL clauses absorb an exception; that is, they catch an
exception propagating out of the try_block, and direct execution into the associated
handler_block. Propagation of the exception, by default, then ends. Within the lexical
scope of a handler, it is possible to explicitly cause propagation of the same exception to
resume (this is called reraising the exception), or it is possible to raise some new
exception.
The RERAISE statement is allowed in any handler statements and causes the current
exception to be reraised. Propagation of the caught exception resumes.
The RAISE (exception_name) statement is allowed anywhere and causes a particular
exception to start propagating. For example:
TRY
sort(); /* Call a function that may raise an exception.
* An exception is accomplished by longjumping
* out of some nested routine back to the TRY
* clause. Any output parameters or return
* values of the called routine are therefore
* indeterminate.
*/
CATCH (pthread_cancel_e)
printf("Alerted while sorting\n"); RERAISE;
CATCH_ALL
printf("Some other exception while sorting\n"); RERAISE;
ENDTRY
In the preceding example, if the pthread_cancel_e exception propagates out of the
function call, the first printf is executed. If any other exception propagates out of sort,
the second printf is executed. In either situation, propagation of the exception resumes
because of the RERAISE statement. (If the code is unable to fully recover from the
error, or does not understand the error, it needs to do what it did in the previous example
and further propagate the error to its callers.)
The following shows the syntax for an epilogue:
TRY try_block
[FINALLY final_block]
ENDTRY
The final_block is executed whether the try_block executes to completion without
raising an exception, or if an exception is raised in the try_block. If an exception is
raised in the try_block, propagation of the exception is resumed after executing the
final_block.
9− 2 Tandem Computers Incorporated 124245