home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_02_11 / 2n11070a < prev    next >
Text File  |  1991-09-06  |  2KB  |  44 lines

  1. program UserRuntimeErrorHandling;
  2. var
  3.   ExitSave : pointer;                           { System's exit routine }
  4.   DataSegment : word;                           { Saved DS register }
  5.  
  6.   { *** Application's declaration part *** }
  7.  
  8. {SF+}
  9.  
  10. procedure RuntimeErrorHandler;
  11. begin
  12.  
  13.   { *** Application's error handler
  14.     Runtime error code in ExitCode -- See Turbo Pascal Manual *** }
  15.  
  16.  ExitProc := @RuntimeErrorHandler;
  17.  asm
  18.    mov sp, bp;                                  { Setup stack frame       }
  19.    mov ds, DataSegment;                         { Restore DS register     }
  20.    pop bx;                                      { Pop flags               }
  21.    pop ax;                                      { Pop return address, ofs }
  22.    pop ax;                                      { Pop return address, seg }
  23.    mov ax, WORD PTR ErrorAddr + 2;              { Get error address, seg }
  24.    add ax, $10;                                 { Adjust error addr, seg }
  25.    add ax, PrefixSeg;
  26.    push ax;                                     { Push error address, seg }
  27.    mov ax, WORD PTR ErrorAddr;                  { Get error address, ofs }
  28.    push ax;                                     { Push error address, ofs }
  29.    push bx;                                     { Push flags }
  30.   end;
  31. end; { RuntimeErrorHandler }
  32.  
  33. {$F-}
  34.  
  35. begin
  36.   ExitSave := ExitProc;
  37.   ExitProc := @RuntimeErrorHandler;
  38.   DataSegment := DSeg;
  39.  
  40.   { *** Application's code area *** }
  41.  
  42.   ExitProc := ExitSave;
  43. end.
  44.