Try to handle an exception in the place it occurs. There is some processing overhead incurred with exception percolation.
The following figure shows an example of ILE C source code for handling exceptions. Below the figure is an example of an exception that can occur and the steps the code takes to handle the exception.
Figure 39. T1520XH7 -- ILE C Source for Exception Handling
#include <stdio.h>
#include <except.h>
#include <signal.h>
#include <lecond.h>
void handler1(_INTRPT_Hndlr_Parms_T * __ptr128 parms)
{
printf("In handler1: will not handle the exception\n");
}
void handler2(_INTRPT_Hndlr_Parms_T * __ptr128 parms)
{
printf("In handler2: will not handle the exception\n");
}
void handler3(_FEEDBACK *condition, _POINTER *token, _INT4 *result_code,
_FEEDBACK *new_condition)
{
printf("In handler3: will not handle the exception\n");
}
void handler4(_INTRPT_Hndlr_Parms_T * __ptr 128 parms)
{
printf("In handler4: will not handle the exception\n");
}
void fred(void)
{
_HDLR_ENTRY hdlr = handler3;
char *p = NULL;
#pragma exception_handler(handler2, 0, 0, \
_C2_MH_ESCAPE | _C2_MH_FUNCTION_CHECK)
CEEHDLR(&hdlr, NULL, NULL);
#pragma exception_handler(handler1, 0, 0, _C2_MH_ESCAPE)
*p = 'x'; /* exception */
}
int main(void)
{
signal(SIGSEGV, SIG_DFL);
#pragma exception_handler(handler4, 0, 0, \
_C2_MH_ESCAPE | _C2_MH_FUNCTION_CHECK)
fred();
}
|
The sequence of exceptions and handling actions that occur when the source code in Figure 39 is run is:
(C) Copyright IBM Corporation 1992, 2005. All Rights Reserved.