In the following example, if either a divide-by-zero fault or an invalid index fault occurs at run time, the fault condition is discarded and control transfers to the compound statement in this ON statement. The stack history information is written to the array row FAULTARRAY, and the fault number of the fault that occurred is stored in FAULTNO.
ON ZERODIVIDE OR INVALIDINDEX [FAULTARRAY:FAULTNO]:
BEGIN
REPLACE FAULTARRAY[8] BY FAULTNO FOR * DIGITS;
WRITE(LINE, 22, FAULTARRAY);
REPLACE FAULTARRAY BY " " FOR 22 WORDS;
CASE FAULTNO OF
BEGIN
1: DIVISOR := 1;
4: INDEX := 100;
END;
GO BACK;
ENDIn the following example, if either of the specified faults occur at run time, the fault condition is discarded and control is transferred to the assignment statement in the ON statement. After execution of the assignment statement, execution continues with the statement following the ON statement.
ON MEMORYPROTECT OR LOOP: Q:= 2
The following example disables the interrupt associated with the exponent under flow fault.
ON EXPONENTUNDERFLOW % Disabling ON Statement
In the following example, if any fault occurs, the statement HANDLEFAULTS(Z) is called as a procedure. The stack history information is written to the location indicated by the pointer expression POINTR + 2, and the fault number of the fault that occurred is stored in Z.
ON ANYFAULT [POINTR + 2:Z],HANDLEFAULTS(Z)

