`prev Menu next`

Exception Handling ☆☆☆
An error that occurs during the execution of a program is called an exception.
Exception handling enables the program to continue by describing the process that shall be executed when an exception has occurred.
Example 1. A program without exception handling.

    10 OPTION ANGLE DEGREES
    20 SET WINDOW 0,180,-10,10
    30 FOR x=0 TO 180 STEP 0.1
    40    PLOT LINES: x,TAN(x);
    50 NEXT x
    60 END

This program stops at x=90 for an exception.
Example 2. A program with exception handling.

    10 OPTION ANGLE DEGREES
    20 SET WINDOW 0,180,-10,10
    30 FOR x=0 TO 180 STEP 0.1
    40    WHEN EXCEPTION IN
    50       PLOT LINES: x,TAN(x)
    60    USE
    70       PLOT LINES
    80    END WHEN
    90 NEXT x
    100 END

If an exception occurs on the 50-line, the control jumps to the 70-line.
That is, on this program, the 70-line is the process that is executed when an exception has occurred on the 50-line.