What is Trap Handling? [ Trap Handling Programmer's Guide ] MPE/iX 5.0 Documentation
Trap Handling Programmer's Guide
What is Trap Handling?
When a trap situation is detected and process execution is interrupted,
control passes to the MPE XL trap subsystem, which determines what action
is to be taken in response to the trap. In most instances, the trap
subsystem outputs an appropriate error message and aborts the offending
process. Generally, this is what you want to happen. You can, however,
avoid the abort by writing and arming one or more of the types of trap
handlers allowed by MPE XL:
* Arithmetic trap handler, for errors of an arithmetic nature
* Library trap handler, for errors detected during the execution of a
system library procedure
* System trap handler, for errors detected during execution of a system
intrinsic
* CONTROL-Y trap handler, for handling subsystem breaks during
interactive sessions
If traps are enabled and your trap handler is armed, the MPE XL trap
subsystem does the following when an error is detected:
* Suppresses output of the normal error message
* Transfers control to the trap handling procedure you defined
* Passes one or more parameters describing the error to your trap
handling procedure
Your trap handling procedure may attempt to analyze or recover from the
error, or it may execute some other programming path. Upon exit from the
trap handling procedure, control usually returns to the instruction
following the one that activated the trap. In the case of library traps,
however, you can specify that the process should abort when control exits
from the trap handler.
User-defined trap handling procedures are armed or disarmed by means of
the system intrinsics described later. If a user-defined trap handler is
not armed and traps are enabled, the MPE XL trap subsystem is invoked
when a trap occurs.
Arming Versus Enabling Traps
There is a difference between enabling traps and arming a trap handler.
Enabling a trap means that the occurrence of a trap condition is not
ignored. Arming a trap handler is required so that, on a trap condition,
a user-written routine is invoked and can take appropriate recovery
actions. The following list summarizes what can occur when an arithmetic
trap condition arises:
1. If a trap is enabled and a corresponding trap handler is armed,
the user-written trap handler is invoked whenever a trap condition
occurs.
2. If a trap is enabled but no trap handler is armed, one of two
situations applies:
a. If you have executed an HP Pascal/XL TRY statement, control is
passed to the RECOVER block by doing an ESCAPE.
b. If you have not executed an HP Pascal/XL TRY statement, an
error message is output and the process aborts.
3. If a trap is disabled, irrespective of whether a trap handler is
armed, the trap is ignored, and execution of the process continues
without any interruption.
Voluntary Trap Situations
Although trap situations are usually involuntary, there is one kind of
trap that you can cause intentionally. This is the subsystem break
(CONTROL-Y), and it can be entered during interactive sessions. You can
write a trap handling procedure for such situations and arm or disarm
your trap handler by using an intrinsic.
Locating Further Information
Refer to individual programming language manuals for language-specific
information on trap handling.
MPE/iX 5.0 Documentation