Error messages

From BeebWiki
Revision as of 19:44, 10 September 2023 by Jgharston (talk | contribs) (Added RISC-V.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

BBC computer errors are an 8-bit number and a string.

   +---------------------------+
   | error number, 1 byte      |
   +---------------------------+
   | error string, 1-254 bytes |
   +---------------------------+
   |            &00            |
   +---------------------------+

Error numbers < 128 (ie, b7=0) are language errors, error numbers > 127 (ie b7=1) are system (ie MOS, filing system, utility, etc.) errors. As BASIC's errors are all <64 (ie b7=0, b6=0), any error numbers used within a program for its own purposes should be 64-127 (ie b7=0, b6=1).

While the text of an error message can vary between situations, the error number must be consistant. For example, error 214 (&D6) is File not found, the string can vary between File not found, Not found, XXXX not found and File 'XXXX' not found. However, the error number is consistantly 214.

On 32-bit platforms the error number is a 32-bit word, error numbers < 256 are the same as 8-bit error numbers.

Raising an error

6502

 BRK
 EQUB err_num
 EQUS err_string$
 EQUB 0

Z80

 RST  &38
 DEFB err_num
 DEFM err_string$
 DEFB 0

6809/6811/6812

 SWI
 DEFB err_num
 DEFM err_string$
 DEFB 0

80x86

 INT  &4F
 DEFB err_num
 DEFM err_string$
 DEFB 0

PDP11

 EMT  15
 DEFB err_num
 DEFM err_string$
 DEFB 0

Errors can also be returned to the caller:

 ADR   PDP11ErrorBlock,R0  ; Point R0 to error block
 SEV                       ; Set Overflow flag
 RTS   PC                  ; Return to caller
 .PDP11ErrorBlock
 DEFB err_num
 DEFM err_string$
 DEFB 0

32016

Errors cannot be generated within PanOS, but they can be returned to the caller:

 ADDR PanErrorBlock,R0   ; Point R0 to error block
 MOV  [R0],R1            ; R1=error number
 SEF                     ; Set error flag
 RET 0                   ; Return to caller
 .PanErrorBlock
 EQUD err_num16bit       ; error numbers < 256 are the same as 8-bit error numbers
 EQUB LEN err_string$
 EQUS err_string$

ARM

 ADR  R0,ArmErrorBlock   ; ARM error block is word, string, &00
 SWI  "OS_GenerateError" ; &2B
 .ArmErrorBlock
 EQUD err_num32bit       ; error numbers < 256 are the same as 8-bit error numbers
 EQUS err_string$
 EQUB 0

Errors can also be returned to the caller:

 ADR   R0,ArmErrorBlock  ; Point R0 to error block
 CMPVC R0,#1<<31         ; These two instructions
 CMNVC R0,#1<<31         ;  set the Overflow flag
 MOV   PC,LINK           ; Return to caller
 .ArmErrorBlock
 EQUD  err_num32bit      ; error numbers < 256 are the same as 8-bit error numbers
 EQUS  err_string$
 EQUB  0

RISC-V

 ECALL &AC000F
 EQUD  err_num32bit      ; error numbers < 256 are the same as 8-bit error numbers
 EQUS  err_string$
 EQUB  0

BBC BASIC

In BASICs that support the ERROR command (BASIC V and some earlier versions):

 ERROR err_num,err_string$

See also