
Writing an Exception Handler
Developing TACL Routines
107365 Tandem Computers Incorporated
3–19
Types of Exception
Handlers
Exception handlers can be divided into two types, depending on how they return
control:
Release handlers that relinquish control to the calling procedure
Keep handlers that retain control regardless of exceptions (usually for security
purposes)
A routine can contain both types of exception handlers.
Constructing an Exception
Handler
Use the built-in functions in Table 3-2 to construct exception handlers.
Table 3-2. Functions That Support Exception Handlers
Function
Description
#ERRORNUMBERS
Returns the most recent TACL error.
#ERRORTEXT
Intercepts error text that would have been written to the OUT file if there
had been no exception handler.
#EXCEPTION
Returns the type of exception that invoked the exception handler:
_CALL if the routine containing #EXCEPTION was invoked normally.
The name of the exception if the routine was invoked in response to an
exception that was listed in a #FILTER function.
#FILTER
Specifies the types of exceptions a routine can handle.
#RAISE
Causes an exception to occur.
#RETURN
Returns immediately from the routine.
As shown in Figure 3-12, a routine that contains an exception handler has the
following structure:
It begins with a #CASE statement immediately after the ?SECTION directive. This
#CASE statement uses the #EXCEPTION built-in function to determine which
exception occurred. The #CASE statement includes the following:
The first label in the #CASE is _CALL. This exception occurs as part of normal
processing when a calling program invokes the routine.
Remaining labels identify the exceptions for which the handler can be
invoked. Each case contains statements that handle the associated type of
exception.
Do not place a #FRAME call before the #CASE statement.
The body of code for the routine follows the #CASE statement. This code includes
a #FILTER call that lists the exceptions for which this code is protected—and
which are defined as labels in the #CASE statement. You can change the setting of
#FILTER as necessary during processing to enable or disable processing of specific
exceptions.
The routine ends with an #UNFRAME function.