TRY guarded-statements EXCEPT "|" exception-name { "," exception-name ... } "=>" action-statement "|" exception-name "(" parameter-name ")" "=>" action-statement [ ELSE statements ] END
The TRY-EXCEPT statement guards statements between TRY and EXCEPT with the exception handlers between EXCEPT and END. An exception raised by a guarded-statement is handled by action-statement which has a matching handler for the exception raised, or by ELSE statements, if present. If an exception is caught, execution continues with the statement following the END, otherwise the exception is passed on to the enclosing scope.
Note: The else clause of a TRY-EXCEPT statement may catch a RETURN or an EXIT, as they are defined as internal exceptions.
EXCEPTION Failure(Severity); TYPE Severity = {Low, Medium, High}; ... TRY ... EXCEPT | IO.Error => IO.Put("An I/O error occurred.") | Lex.Error => IO.Put("Unable to convert datatype.") | Severity(x) => IF x = Severity.Low THEN IO.Put("Not bad") ELSE IO.Put("Bail out") END END;