HP 3000 Manuals

Examples [ Trap Handling Programmer's Guide ] MPE/iX 5.0 Documentation


Trap Handling Programmer's Guide

Examples 

To use the XLIBTRAP intrinsic to arm/disarm a user-written library trap
handler, you must do the following:

 *  Declare the intrinsic in your source, using whatever conventions are
    appropriate to your language.

 *  Declare the trap handling procedure, using the appropriate formal
    parameters.

Example 5-1 is an HP Pascal/XL code excerpt that describes the algorithm
for implementing user handling of library traps:

Example 5-1.  Software Library Trap Handler 

     (* The following is an example of using the XLIBTRAP intrinsic to catch
        Pascal library errors.  In this example, the user trap handler ignores
        the file close errors and aborts the program for other library errors. *)

     (* Declare the following record as the information record.                *)

     TYPE
        Pstmrk = record
           user_SpaceID,
           user_Offset,
           user_StackPointer,
           user_DataPointer : integer;
        end;  (* record *)

     VAR
        Paserr_CloseError : integer;
        oldplabel : integer;

     PROCEDURE XLIBTRAP; intrinsic;

     PROCEDURE My_Library_Trap_Handler ( Var info_rec  : Pstmrk;
                                         Var errorcode : integer;
                                         Var abortflag : integer);

     BEGIN

     (* ignore file close errors *)

        if ( errorcode = Paserr_CloseError ) then
           BEGIN
           writeln ('File close error, continue execution');
           abortflag := 0;   (* no abort *)
           END
        else
           abortflag := 1;   (* abort *)
     END;  (* My_Library_Trap_Handler *)

     BEGIN

     (* arming the user-written software library trap handler *)

        XLIBTRAP( waddress(My_Library_Trap_Handler), oldplabel);

     (* remainder of program *)
     END.



MPE/iX 5.0 Documentation