Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Use a Code Panel for the example code

...

The following example illustrates the structure of an error handler with a few responding error codes:

 
Code Block
languagenone
include "errors.def"                ; error call/code definitions

...


include "stdio.def"                 ; standard input/output definitions

...


include "director.def"              ; director call definitions

...



.install    xor  a                  ; zero A

...


            ld   b,a                ; zero B

...


            ld   hl,error_han       ; address of error handler

...


            oz   OS_Erh             ; install new error handler...

...


            ...                     ; main application goes here...

...


; 

...


; error handler entry:

...



.error_han  ret  z                  ; error is fatal, so exit back to system

...


            cp   RC_ESC             ; check for <ESC>

...


            jr   nz, not_escape

...


            ld   a, SC_ACK          ; acknowledge RC_ESC = SC_ACK

...


            oz   OS_Esc             ; escape processing call

...


            ld   a, RC_ESC          ; error code

...


            oz   GN_Esp             ; get extended address to error message

...


            oz   GN_Soe             ; write message to standard output

...


            or   a                  ; Fc = 0, Fz = 0

...


            ret

...



.not_escape cp   rc_quit            ; check for KILL request

...


            jr   nz, not_quit

...


                                    ; code to close files and de-allocate

...


                                    ; memory goes here...

...


            xor  a                  ; no error message on exit...

...


            oz   OS_Bye             ; force remove application from system

...



.not_quit   or   a                  ; Fc = 0, Fz = 0

...


            ret

The error handler above responds to an Escape condition and a KILL request. All other errors are 'ignored' with a display of the system message corresponding to the error code. Please note that no registers are changed, except Fc (Carry) and Fz (Zero) flags. Your error handler might respond to RC_DRAW and issue a routine to redraw the application windows. Remember that your routines might change registers that they're not supposed to regarding the outside world of the error handler.

...