Protecting a Process from Faults

A fault is an invalid action that is detected by the hardware, such as an attempt to divide by zero. In general, a process is discontinued if it encounters a fault. However, ALGOL and NEWP provide a feature that can be used to allow the process to continue normal execution after most faults. The ON statement specifies actions to be taken if a fault occurs. In addition, the ON statement can be used to interrogate the type of fault and the stack history. The stack history value returned is identical in format to that returned by the STACKHISTORY task attribute.

The ON statement can specify which particular fault types it is to handle, or can include the ANYFAULT clause to handle all eligible faults. Certain faults, such as stack overflows, cannot be handled by the ON statement. If any fault occurs that can be handled, the following ON statement stores the stack history into array FAULTARRAY and the number into FAULTNO. The statement then invokes the procedure HANDLEFAULTS, passing the fault number to it as a parameter:

ON ANYFAULT [FAULTARRAY:FAULTNO], HANDLEFAULTS(FAULTNO);

In addition, the C language supports a signals mechanism that can be used for fault handling. The signals mechanism is among the C language extensions that support the POSIX environment. For an overview of signals, refer to the POSIX User's Guide.