HP 3000 Manuals

Run-Time Trap Handling [ HP COBOL II/XL Reference Manual ] MPE/iX 5.0 Documentation


HP COBOL II/XL Reference Manual

Run-Time Trap Handling 

The HP COBOL II compiler handles run-time traps for a variety of run-time
error conditions.  You can control your program's response to these
conditions.  This section:

   *   Describes the traps that the HP COBOL II compiler supports.

   *   Explains how to specify what actions should be taken when run-time
       errors occur.

   *   Explains when and how to enable the trap mechanism.

Supported Traps 

The HP COBOL II compiler supports the following traps:

   *   Illegal ASCII digit (Error 711)--This error occurs if the program
       is compiled with the $CONTROL VALIDATE option and an illegal ASCII
       digit is encountered.  It also occurs when an unsigned number is
       detected in a signed numeric field or vice-versa.

   *   Illegal decimal digit (Error 710)--This error occurs if the
       program is compiled with the $CONTROL VALIDATE option and an
       illegal decimal digit is encountered.  It also occurs when an
       unsigned number is detected in a signed numeric field or
       vice-versa.

   *   Range Error (Error 751)--This error occurs if the program is
       compiled with the $CONTROL BOUNDS option and one of the following
       occurs:
          *   The identifier named in an OCCURS DEPENDING ON clause is
              out of bounds.
          *   A subscript or index is out of bounds.
          *   A reference modification is out of bounds.[REV BEG]
          *   For some COBOL functions, parameter is out of range.[REV
              END]
       [REV BEG]

   *   No Size Error Phrase (Error 747)--This[REV END] error occurs:
          *   If a division by zero or other size error occurs without an
              ON SIZE ERROR phrase.[REV BEG]
          *   For COBOL functions, IEEE traps can occur for invalid
              parameters.
          *   For COBOL functions, XLIBTRAP traps can occur for invalid
              parameters.[REV END]

   *   Invalid GO TO (Error 754)--This error occurs for an alterable GO
       TO that was never altered.  That is, it never specified the target
       of the GO TO statement.

   *   Address Alignment (Error 753)--This error occurs if the program is
       compiled with the $CONTROL BOUNDS option and either the control
       option OPTFEATURES=LINKALIGNED or LINKALIGNED16 and a parameter is
       passed that is not on a 32-bit or 16-bit boundary, respectively.

   *   Paragraph Stack Overflow (Error 748)--This error occurs when a
       program is compiled with the $CONTROL BOUNDS option and one of the
       following occurs:
          *   A recursive PERFORM.
          *   Too many nested PERFORM statements have the same common
              exit point.
          *   Too many illegal GO TO statements are used to jump out of
              PERFORMed paragraphs.

Handling Run-Time Errors with COBRUNTIME 

The default action when one of these errors occurs is to print an error
message and abort the program.  To specify an action other than the
default, you need to[REV BEG] do both of the following:

   *   Compile your program with $CONTROL VALIDATE and $CONTROL
       BOUNDS.[REV END]
   *   Set a global variable, called COBRUNTIME, to a set of
       characters[REV BEG] before running the program.[REV END]

A global variable is similar to a job control word.  Each character
position in COBRUNTIME corresponds to a particular error condition.  The
letter in each character position of COBRUNTIME instructs the compiler
how to handle that particular error, as shown in Table H-7 . 

          Table H-7.  Run-Time Error Handling Options 

----------------------------------------------------------------------------------------
|              |                                                                       |
|    Option    |                                Meaning                                |
|              |                                                                       |
|  A or blank  | Print the error message and abort (default).                          |
|              |                                                                       |
|      C       | Print the error message and continue.                                 |
|              |                                                                       |
|      D       | Print the error message and enter debug mode.                         |
|              |                                                                       |
|      I       | Ignore the error.  (Continue without printing an error message).      |
|              |                                                                       |
|      M       | Print the error message, change the illegal digit to some legal       |
|              | digit, and continue.  This option is only valid for illegal decimal   |
|              | or ASCII digit errors.  (See character position 1 in Table H-8 .)  |
|              | When used for other errors, M is treated as a blank.                  |
|              |                                                                       |

|      N       | Change the illegal digit to a legal digit and continue without        |
|              | printing an error message.[REV BEG] This option is only valid for     |
|              | illegal decimal or ASCII digit errors in positions 1, 7, and 8.  See  |
|              | the description of character positions 1, 7, and 8 in Table H-8    |
|              | for details.  When used in other positions,[REV END] N is treated as  |
|              | a blank.                                                              |
|              |                                                                       |
----------------------------------------------------------------------------------------


NOTE The M and N options alter the offending source fields[REV BEG] unless the source field is defined as PIC X and the target is PIC 9 DISPLAY.[REV END]
Setting COBRUNTIME. You set the run-time environment using the MPE XL SETVAR command with the variable COBRUNTIME. For example: SETVAR COBRUNTIME "string" In the above example "string" is a string of[REV BEG] nine[REV END] either uppercase or lowercase characters representing the run-time options A, C, D, I, M, N, or blank, as shown in Table H-7 . A blank in the string is interpreted as "A", or "Abort," the default. Each character position in the string represents a specific trap that you can request, as shown in Table H-8 . Table H-8. Character Position in Specific Traps ------------------------------------------------------------------------------- | | | | Character | | | Position | Trap Type | | | | ------------------------------------------------------------------------------- | | | | 1 | Illegal ASCII or decimal digit. | | | | ------------------------------------------------------------------------------- | | | | 2 | Range error (OCCURS DEPENDING ON identifier, subscript, | | | index, or reference modification out of bounds). | | | | ------------------------------------------------------------------------------- | | | | 3 | No SIZE ERROR phrase. | | | | ------------------------------------------------------------------------------- | | | | 4 | Invalid GO TO. | | | | ------------------------------------------------------------------------------- | | | | 5 | Address Alignment. | | | | ------------------------------------------------------------------------------- | | | | 6 | Paragraph stack overflow (recursive PERFORMs or too many | | | PERFORMs with a common exit point).[REV BEG] | | | | ------------------------------------------------------------------------------- | | | | 7 | Leading blanks in a numeric field. If this position | | | contains I, leading blanks in a numeric field are ignored. | | | If this position contains N, leading blanks are changed to | | | zeros. If this position contains a value other than N or I, | | | the action entered in character position 1 is used. | | | | ------------------------------------------------------------------------------- | | | | 8 | Unsigned number in signed numeric field or signed number in | | | unsigned numeric field. If this position contains I, the | | | invalid sign is ignored. If this position contains N, the | | | invalid sign is corrected. If this position contains a | | | value other than N or I, the action entered in character | | | position 1 is used. | | | | ------------------------------------------------------------------------------- | | | | 9 | Only affects a NUMERIC class condition with a PACKED-DECIMAL | | | identifier. If this field contains the character I, then | | | the following conditions do not make a NUMERIC test false: | | | | | | * A signed value in an unsigned PACKED-DECIMAL field. | | | * An unsigned value in a signed PACKED-DECIMAL field. | | | * Any invalid sign nibble (half-byte). | | | | | | If this field contains anything other than I, the above | | | conditions make the NUMERIC class condition false.[REV END] | | | | ------------------------------------------------------------------------------- M can only appear in the first character position, and N can only appear in character positions 1, 7, and 8. This is because the action taken by M and N only applies to an illegal ASCII or decimal digit errors. If either letter appears in any other character position, it is treated as a blank. If character positions 7 or 8 are blank or are not equal to N or I, the action specified in character position 1 is used. [REV BEG] Setting COBRUNTIME to the following will closely simulate HP COBOL II/V actions: SETVAR COBRUNTIME "MCCAAANNI" [REV END] Example. For example, for a program compiled with the control options VALIDATE and BOUNDS, the following MPE XL command sets COBRUNTIME: [REV BEG] SETVAR COBRUNTIME "M_IDCANNI" The above SETVAR command has the following effects when you run the program: * Fixes any invalid digits that are found, prints an error message, and continues running (M in position 1). * Aborts if a trap on an OCCURS DEPENDING ON item, a subscript, an index, or a reference modification goes out of bounds (blank in position 2). * Ignores any traps that occur on size errors, division by zero, or illegal intrinsic function parameters, if these are used without an ON SIZE ERROR clause (I in position 3). * Prints an error message and places you in debug mode if an invalid GO TO error occurs (D in position 4). * Prints an error message and continues on an address alignment trap (C in position 5). * Aborts on illegal PERFORMs or illegal GO TOs out of performed paragraphs, or on paragraph stack overflow (A in position 6). * Changes leading blanks in numeric fields to zeros without reporting an error (N in position 7). * Fixes illegal signs in numeric fields without reporting an error (N in position 8). * Does not return a false NUMERIC class condition on a PACKED-DECIMAL data item if the sign of the data item is illegal (I in position 9).[REV END] Refer to the HP COBOL II/XL Programmer's Guide for more discussion and examples of handling errors. [REV BEG] The COBOL Trap Mechanism and Other Languages [REV END][REV BEG] In order to work, the COBOL trap mechanism must be armed for the ON SIZE ERROR phrase, $CONTROL VALIDATE command, and $CONTROL BOUNDS command. (The traps must actually be enabled and armed. However, in this section, the term armed implies enabled and armed. For more details, see the Trap Handling Programmer's Guide.) Besides the HP COBOL II run-time library, the COBOL trap mechanism uses the DEBUG macro file COBMAC.PUB.SYS.[REV END] [REV BEG] The procedure COBOLTRAP is provided in the HP COBOL II run-time library to arm the[REV END] COBOL trap mechanism. For an HP COBOL II main program, the compiler automatically calls COBOLTRAP.[REV BEG] When the COBOL trap mechanism is armed and an error occurs that activates a trap, the HP COBOL II run-time library gains control.[REV END] For operating efficiency and compatibility with other HP programming languages, the HP COBOL II/XL compiler does not call COBOLTRAP for COBOL subprograms. If an HP COBOL II subprogram is called by a program or subprogram written in a language other than COBOL, it is your responsibility to arm the COBOL trap mechanism before the call. [REV BEG] If the COBOL trap mechanism is armed and if a subprogram in another language is called, problems may occur if trap handling is not set for that language. In particular, these problems may occur: * FORTRAN ON statements may not work. * Pascal TRY/RECOVER may not work for RANGE errors. * Business Basic ON statements may not work. The COBOL trap mechanism will produce a COBOL run-time error instead of the appropriate language error. For example, a Pascal run-time error may be reported as "NO SIZE ERROR PHRASE (COBERR 747)".[REV END] The procedure COBOLTRAP has no parameters. To call it, simply code: CALL "COBOLTRAP". The following are recommended programming steps for three possible trap-handling scenarios: * HP COBOL II programs and subprograms calling an HP COBOL II subprogram: Because the COBOL trap mechanism is armed in the HP COBOL II main program, there is no need to call COBOLTRAP in the subprogram. * HP COBOL II programs and subprograms calling a subprogram written in another language: Step 1: Arm or disarm the trap mechanism for the other language. Step 2: Issue a CALL statement calling the other language subprogram or procedure. Step 3: Arm the COBOL trap mechanism by calling the COBOLTRAP procedure. * Programs and subprograms written in other languages calling an HP COBOL II subprogram: Step 1: Arm the COBOL trap mechanism by calling the COBOLTRAP procedure. Step 2: Call the HP COBOL II subprogram. Step 3: Arm or disarm the trap mechanism for the other language. Example 1. [REV BEG] This example shows how an HP COBOL II/XL program calling a Pascal procedure can arm the software traps for Pascal and then rearm the traps for HP COBOL II/XL. This example sets the trap mechanism to the default for languages such as Pascal, FORTRAN, and HP C. 001000 IDENTIFICATION DIVISION. 001100 PROGRAM-ID. COBOLPROF. 001300 DATA DIVISION. 001400 WORKING-STORAGE SECTION. 001500 77 PARM1 PIC S99V99 COMP. 001600 77 PARM2 PIC X(18). 001700 PROCEDURE DIVISION. 001710 P1. 001800* Step 1: call the procedure pastrap to arm the software trap 001900* for pascal 002000 CALL "PASTRAP". 002100* Step 2: call the pascal procedure pasprog 002200 CALL "PASPROG" USING PARM1 PARM2. 002300* Step 3: arm COBOL traps again 002400 CALL "COBOLTRAP". 002500 STOP RUN. The procedure Pastrap is coded as follows: $subprogram$ program example_1; procedure xaritrap; intrinsic; procedure xlibtrap; intrinsic; procedure hpenbltrap; intrinsic; procedure pastrap; var oldmask, oldplabel : integer; begin xaritrap(0,0,oldmask,oldplabel); { disarm arithmetic traps } xlibtrap(0,oldplabel); { disarm library traps } { enable all traps but IEEE } hpenbltrap(hex('fff83fff'),oldmask); { set to Pascal default } end; begin end. [REV END] Example 2. [REV BEG] This example shows how an HP COBOL II/XL program calling a FORTRAN procedure can arm the software traps for FORTRAN and then rearm the traps for HP COBOL II/XL. This example saves and restores the state of the trap mechanism before and after the call to the non-COBOL subprogram. This method must be used if the called subprogram changes the default trap mechanism. For example, if a FORTRAN subprogram uses an ON statement, this method retains the state of the subprogram's trap mechanism. 001000 IDENTIFICATION DIVISION. 001100 PROGRAM-ID. IO888E. 001200 DATA DIVISION. 001300 WORKING-STORAGE SECTION. 001400 1 buffer. 001500 5 c pic s9(9) comp value 0. 001600 1 trap-stuff. 001700 5 old-mask pic s9(9) comp value 0. 001800 5 old-plabel pic s9(9) comp value 0. 001900* enable all but IEEE traps 002000 5 old-enblemask pic s9(9) comp value %37776037777. 002100 5 old-libplabel pic s9(9) comp value 0. 002200 5 dummy-var pic s9(9) comp. 002300 procedure division. house. 002400 perform 2 times 002500 perform restore-fortran-state 002600 call "fortransub" using buffer 002700 perform save-fortran-state 002800 display c 002900 end-perform 003000 stop run. 003100 003200 save-fortran-state. 003300 call intrinsic "XARITRAP" using 0 0 old-mask old-plabel 003400 call intrinsic "HPENBLTRAP" using 0 old-enblemask 003500 call intrinsic "XLIBTRAP" using 0 old-libplabel 003600 call "coboltrap". 003700 restore-fortran-state. 003800 call intrinsic "XARITRAP" using old-mask old-plabel 003900 dummy-var dummy-var 004000 call intrinsic "HPENBLTRAP" using old-enblemask dummy-var 004100 call intrinsic "XLIBTRAP" using old-libplabel dummy-var. [REV END] Example 3. [REV BEG] This example shows how a Pascal program calling an HP COBOL II/XL subprogram can arm the software traps for HP COBOL II/XL and then rearm the traps for Pascal. program pasprog; module cobol_trap_handling; export procedure savepascaltraps; procedure restorepascaltraps; procedure coboltrap; implement { private save variables for trap handling } var o_a_mask, o_a_plabel, o_l_mask, o_l_plabel, o_e_mask : integer; procedure xaritrap; intrinsic; procedure xlibtrap; intrinsic; procedure hpenbltrap; intrinsic; procedure coboltrap; external; procedure savepascaltraps; begin { save old values } xaritrap(0,0,o_a_mask,o_a_plabel); xlibtrap(0,o_l_plabel); hpenbltrap(0,o_e_mask); end; procedure restorepascaltraps; var dummy : integer; begin { restore old pascal values } xaritrap(o_a_mask,o_a_plabel,dummy,dummy); xlibtrap(o_l_plabel,dummy); hpenbltrap(o_e_mask,dummy); end; end; import cobol_trap_handling; var i : integer; procedure cobolsubprog(var parm1: integer); external cobol; begin i:=-33; savepascaltraps; coboltrap; cobolsubprog(i); restorepascaltraps; end. [REV END] [REV BEG] 001000$CONTROL SUBPROGRAM,OPTFEATURES=LINKALIGNED 001100 IDENTIFICATION DIVISION. 001200 PROGRAM-ID. COBOLSUBPROG. 001300 DATA DIVISION. 001400 WORKING-STORAGE SECTION. 001500 01 J PIC ----,---,---. 001600 LINKAGE SECTION. 001700 01 I PIC S9(9) BINARY. 001800 PROCEDURE DIVISION USING I. 001900 P1. 002000 MOVE I TO J. 002100 DISPLAY "INPUT PARM WAS" J. [REV END]


MPE/iX 5.0 Documentation