Document revision date: 30 March 2001
[Compaq] [Go to the documentation home page] [How to order documentation] [Help on this site] [How to contact us]
[OpenVMS documentation]

OpenVMS Programming Concepts Manual


Previous Contents Index


Chapter 9
Condition-Handling Routines and Services

This chapter describes the OpenVMS Condition Handling facility and contains the following sections:

Section 9.1 gives an overview of run-time errors.

Section 9.2 gives an overview of the OpenVMS Condition Handling facility, presenting condition-handling terminology and functionality.

Section 9.3 describes VAX system and Alpha system exceptions, arithmetic exceptions, and unaligned access traps on Alpha systems.

Section 9.4 describes how run-time library routines handle exceptions.

Section 9.5 describes the condition value field and the testing and modifying of values.

Section 9.6 describes the exception dispatcher.

Section 9.7 describes the argument list that is passed to a condition handler.

Section 9.8 describes signaling.

Section 9.9 describes types of condition handlers.

Section 9.10 describes types of actions performed by condition handlers.

Section 9.11 describes messages and how to use them.

Section 9.12 describes how to write a condition handler.

Section 9.13 describes how to debug a condition handler.

Section 9.14 describes several run-time library routines that can be established as condition handlers.

Section 9.15 describes how to establish, write, and debug an exit handler.

9.1 Overview of Run-Time Errors

Run-time errors are hardware- or software-detected events, usually errors, that alter normal program execution. Examples of run-time errors are as follows:

When an error occurs, the operating system either returns a condition code or value identifying the error to your program or signals the condition code. If the operating system signals the condition code, an error message is displayed and program execution continues or terminates, depending on the severity of the error. See Section 9.5 for details about condition values.

When unexpected errors occur, your program should display a message identifying the error and then either continue or stop, depending on the severity of the error. If you know that certain run-time errors might occur, you should provide special actions in your program to handle those errors.

Both an error message and its associated condition code identify an error by the name of the facility that generated it and an abbreviation of the message text. Therefore, if your program displays an error message, you can identify the condition code that was signaled. For example, if your program displays the following error message, you know that the condition code SS$_NOPRIV was signaled:


%SYSTEM-F-NOPRIV, no privilege for attempted operation

9.2 Overview of the OpenVMS Condition Handling Facility

The operating system provides a set of signaling and condition-handling routines and related system services to handle exception conditions. This set of services is called the OpenVMS Condition Handling facility (CHF). The OpenVMS Condition Handling Facility is a part of the common run-time environment of OpenVMS, which includes run-time library (RTL) routines and other components of the operating system.

The OpenVMS Condition Handling facility provides a single, unified method to enable condition handlers, signal conditions, print error messages, change the error behavior from the system default, and enable or disable detection of certain hardware errors. The RTL and all layered products of the operating system use the CHF for condition handling.

See the OpenVMS Calling Standard for a detailed description of OpenVMS condition handling.

9.2.1 Condition-Handling Terminology

This section defines the terms used to describe condition handling.

exception

An event detected by the hardware or software that changes the normal flow of instruction execution. An exception is a synchronous event caused by the execution of an instruction and often means something generated by hardware. When an exception occurs, the processor transfers control by forcing a change in the flow of control from that explicitly indicated in the currently executing process.

Some exceptions are relevant primarily to the current process and normally invoke software in the context of the current process. An integer overflow exception detected by the hardware is an example of an event that is reported to the process. Other exceptions, such as page faults, are handled by the operating system and are transparent to the user.

An exception may also be signaled by a routine (software signaling) by calling the RTL routines LIB$SIGNAL or LIB$STOP.

condition

An informational state that exists when an exception occurs. Condition is a more general term than exception; a condition implies either a hardware exception or a software-raised condition. Often, the term condition is preferred because the term exception implies an error. Section 9.3.1 further defines the differences between exceptions and conditions.

condition handling

When a condition is detected during the execution of a routine, a signal can be raised by the routine. The routine is then permitted to respond to the condition. The routine's response is called handling the condition.

On VAX systems, an address of 0 in the first longword of a procedure call frame or in an exception vector indicates that a condition handler does not exist for that call frame or vector.

On Alpha systems, the handler valid flag bit in the procedure descriptor is cleared to indicate that a condition handler does not exist.

The condition handlers are themselves routines; they have their own call frames. Because they are routines, condition handlers can have condition handlers of their own. This allows condition handlers to field exceptions that might occur within themselves in a modular fashion.

On VAX systems, a routine can enable a condition handler by placing the address of the condition handler in the first longword of its stack frame.

On Alpha systems, the association of a handler with a procedure is static and must be specified at the time a procedure is compiled (or assembled). Some languages that lack their own exception-handling syntax, however, may support emulation of dynamic specified handlers by means of built-in routines.

If you determine that a program needs to be informed of particular exceptions so it can take corrective action, you can write and specify a condition handler. This condition handler, which receives control when any exception occurs, can test for specific exceptions.

If an exception occurs and you have not specified a condition handler, the default condition handler established by the operating system is given control. If the exception is a fatal error, the default condition handler issues a descriptive message and causes the image that incurred the exception to exit.

To declare or enable a condition handler, use the following system services:

Parallel mechanisms exist for uniform dispatching of hardware and software exception conditions. Exceptions that are detected and signaled by hardware transfer control to an exception service routine in the executive. Software-detected exception conditions are generated by calling the run-time library routines LIB$SIGNAL or LIB$STOP. Hardware- and software-detected exceptions eventually execute the same exception dispatching code. Therefore, a condition handler may handle an exception condition generated by hardware or by software identically.

The Set Exception Vector (SYS$SETEXV) system service allows you to specify addresses for a primary exception handler, a secondary exception handler, and a last-chance exception handler. You can specify handlers for each access mode. The primary exception vector is reserved for the debugger. In general, you should avoid using these vectored handlers unless absolutely necessary. If you use a vectored handler, it must be prepared for all exceptions occurring in that access mode.

9.2.2 Functions of the Condition Handling Facility

The OpenVMS Condition Handling facility and the related run-time library routines and system services perform the following functions:

9.3 Exception Conditions

Exceptions can be generated by any of the following:

Hardware-generated exceptions always result in conditions that require special action if program execution is to continue.

Software-generated exceptions may result in error or warning conditions. These conditions and their message descriptions are documented in the online Help Message utility and in the OpenVMS system messages documentation. To access online message descriptions, use the HELP/MESSAGE command.

More information on using the Help Message utility is available in OpenVMS System Messages: Companion Guide for Help Message Users. That document describes only those messages that occur when the system is not fully operational and you cannot access Help Message.

Some examples of exception conditions are as follows:

There are two standard methods for a Compaq- or user-written routine to indicate that an exception condition has occurred:

9.3.1 Conditions Caused by Exceptions

Table 9-1 summarizes common conditions caused by exceptions. The condition names are listed in the first column. The second column explains each condition more fully by giving information about the type, meaning, and arguments relating to the condition. The condition type is either trap or fault. For more information about traps and faults, refer to the VAX Architecture Reference Manual and Alpha Architecture Reference Manual. The meaning of the exception condition is a short description of each condition. The arguments for the condition handler are listed where applicable; they give specific information about the condition.

Table 9-1 Summary of Exception Conditions
Condition Name Explanation  
SS$_ACCVIO Type: Fault.
  Description Acess Violation.
  Arguments:
  1. Reason for access violation. This is a mask with the following format:
    Bit <0> = type of access violation
    0 = page table entry protection code did not permit intended access
    1 = P0LR, P1LR, or SLR length violation 1


    Bit <1> = page table entry reference

    0 = specified virtual address not accessible
    1 = associated page table entry not accessible


    Bit <2> = intended access

    0 = read
    1 = modify

    Bit <16> = indicates fault on the pre-fetch of the instruction 2
    0 = successful execution
    1 = fault on fetch


    Bit <17> =indicates whether instruction is marked as no execute 2

    0 = not market
    1 = indicates instruction is marked as a fault on execute in its page table entry
  2. Virtual address to which access was attempted or, on some processors, virtual address within the page to which access was attempted.
SS$_ARTRES 2 Type:

Description:

Arguments:

Trap.

Reserved arithmetic trap.

None.

SS$_ASTFLT Type: Trap.
  Description: Stack invalid during attempt to deliver an AST.
  Arguments:
  1. Stack pointer value when fault occurred.
  2. AST parameter of failed AST.
  3. Program counter (PC) at AST delivery interrupt.
  4. Processor status longword (PSL) for VAX or processor status (PS) for Alpha at AST delivery interrupt. 3 For PS, it is the low-order 32 bits.
  5. Program counter (PC) to which AST would have been delivered. 3
  6. Processor status longword (PSL) for VAX or processor status (PS) for Alpha to which AST would have been delivered. 3 For PS, it is the low-order 32 bits.
SS$_BREAK Type:

Description:

Arguments:

Fault.

Breakpoint instruction encountered.

None.

SS$_CMODSUPR Type:

Description:

Arguments:

Trap.

Change mode to supervisor instruction encountered. 4

Change mode code. The possible values are --32,768 through 32,767.

SS$_CMODUSER Type:

Description:

Arguments:

Trap.

Change mode to user instruction encountered. 4

Change mode code. The possible values are --32,768 through 32,767.

SS$_COMPAT 1 Type: Fault.
  Description: Compatibility-mode exception. This exception condition can occur only when executing in compatibility mode. 5
  Arguments: Type of compatibility exception. The possible values are as follows:

0 = Reserved instruction execution

1 = BPT instruction executed

2 = IOT instruction executed

3 = EMT instruction executed

4 = TRAP instruction executed

5 = Illegal instruction executed

6 = Odd address fault

7 = TBIT trap.

SS$_DECOVF 1 2 Type:

Description:

Arguments:

Trap.

Decimal overflow.

None.

SS$_FLTDIV 1 2 Type:

Description:

Arguments:

Trap.

Floating/decimal divide-by-zero.

None.

SS$_FLTDIV_F 1 Type:

Description:

Arguments:

Fault.

Floating divide-by-zero.

None.

SS$_FLTOVF 1 2 Type:

Description:

Arguments:

Trap.

Floating-point overflow.

None.

SS$_FLTOVF_F 1 Type:

Description:

Arguments:

Fault.

Floating-point overflow fault.

None.

SS$_FLTUND 1 2 Type:

Description:

Arguments:

Trap.

Floating-point underflow.

None.

SS$_FLTUND_F 1 Type:

Description:

Arguments:

Fault.

Floating-point underflow fault.

None.

SS$_INTDIV 1 2 Type:

Description:

Arguments:

Trap.

Integer divide-by-zero.

None.

SS$_INTOVF 1 2 Type:

Description:

Arguments:

Trap.

Integer overflow.

None.

SS$_OPCCUS 1 Type:

Description:

Arguments:

Fault.

Opcode reserved for customer fault.

None.

SS$_OPCDEC Type:

Description:

Arguments:

Fault.

Opcode reserved for Compaq fault.

None.

SS$_PAGRDERR Type: Fault.
  Description: Read error occurred during an attempt to read a faulted page from disk.
  Arguments:
  1. Translation not valid reason. This is a mask with the following format:
    Bit <0> = 0
    Bit <1> = page table entry reference
    0 = specified virtual address not valid
    1 = associated page table entry not valid


    Bit <2> = intended access

    0 = read
    1 = modify
  2. Virtual address of referenced page.
SS$_RADRMOD 1 Type:

Description:

Arguments:

Fault.

Attempt to use a reserved addressing mode.

None.

SS$_ROPRAND Type:

Description:

Arguments:

Fault.

Attempt to use a reserved operand.

None.

SS$_SSFAIL Type:

Description:

Arguments:

Fault.

System service failure (when system service failure exception mode is enabled).

Status return from system service (R0). (The same value is in R0 of the mechanism array.)

SS$_SUBRNG 1 2 Type:

Description:

Arguments:

Trap.

Subscript range trap.

None.

SS$_TBIT 1 Type:

Description:

Arguments:

Fault.

Trace bit is pending following an instruction.

None.


1On VAX systems, this condition is generated by hardware.
2On Alpha systems, this condition is generated by software.
3The PC and PSL (or PS) normally included in the signal array are not included in this argument list. The stack pointer of the access mode receiving this exception is reset to its initial value.
4If a change mode handler has been declared for user or supervisor mode with the Declare Change Mode or Compatibility Mode Handler (SYS$DCLCMH) system service, that routine receives control when the associated trap occurs.
5If a compatibility-mode handler has been declared with the Declare Change Mode or Compatibility Mode Handler (SYS$DCLCMH) system service, that routine receives control when this fault occurs.


Previous Next Contents Index

  [Go to the documentation home page] [How to order documentation] [Help on this site] [How to contact us]  
  privacy and legal statement  
5841PRO_026.HTML