Writing an Exception Handler
Developing TACL Routines
3–18
107365 Tandem Computers Incorporated
Writing an Exception
Handler
An exception is an event or condition that requires special handling. If, for example, a
user presses the BREAK key or enters alphabetic data when a number is expected, an
exception occurs. TACL cannot detect a modem disconnect, but can detect and
process other exceptions, including ones you define. TACL recognizes three types of
exceptions:
Pressing the BREAK key
A TACL error, as defined in Section 2, “Developing TACL Programs.”
A user-defined exception, such as an end-of-file, for which special handling may
be necessary.
Any one of these exceptions causes TACL to search for an exception handler. An
exception handler is a portion of code that performs actions after an exception. For
example, if a TACL routine opens one or more files and then purges them when
finished, the user could press the BREAK key while the files are still open. TACL
would then close any open files, but would not purge them. If the routine contained
an exception handler, TACL could close the files before exiting. Activities of exception
handlers can include:
Issuing error messages
Resetting data defaults
Terminating open INLINE processes
Resetting frames or accumulated results
Purging scratch files
Performing INITTERM operations
Passing information to the calling routine
Returning control to the calling routine
If you declare local variables within the body of your routine, determine whether or
not to delete these variables within the exception handler.
If an exception occurs and the current routine has no exception handler, TACL exits
from the routine and returns control to the calling routine. TACL continues to
backtrack through the chain of calling routines, exiting routines as it goes, until it finds
a routine that can process the type of exception that occurred. TACL then reinvokes
that routine to process the exception. If TACL finds no such routine, it performs its
own exception handling—it resets frames and results and, if the exception is of type
_ERROR, displays an error message. Similarly, you can nest routines that contain
exception handlers. TACL uses the first exception handler that can process the type of
exception that occurred.
Exception handlers provide a way to release control and deallocate resources. In
addition, you can write an exception handler that does not permit a user to exit the
routine. In this manner, you can write command shells that define a set of commands
available to users.