Error message from error number?
-
- Posts: 272
- Joined: Tue 18 Jun 2024, 09:32
Error message from error number?
Does any version of BBC BASIC have a means, official or otherwise, of determining an error message (REPORT$) from the error number (ERR), for example to discover that error 16 is '"Syntax error"? As far as I'm aware the answer is no (I don't think any of my versions do) but I'd be interested to learn if anybody knows different.
-
- Posts: 37
- Joined: Thu 05 Apr 2018, 14:08
Re: Error message from error number?
With all BBC BASICs I've examined, ERR and REPORT simply return whatever the current FAULT pointer points to. So, if ERR is 16 then REPORT will give - if the programmer has correctly used the correct error number - a string semantically "Syntax error". But there is nothing analagous to an array of error messages that can be indexed into, something like REPORT$(26) or something.
I think I've seen one implementation where there are error messages internally as a table, eg, 4,"Mistake",5,"Missing ,",6,"Type mismatch", etc. but that's implementation-specific and not user-visible. Most implementations have the errors scattered around the code wherever they are generated, so there's no way to internally look them up anyway.
And then, there's no way to "look up" external errors (ERR>127) as they are external to the language, they could have come from anywhere, another module, a different ROM, a different processor, executed loaded code, executed inline code....
The closest is the Internationalisation module on RISC OS, where applications can use a Messages file to provide territory- and language-specific strings. But that's not indexed by error number, but by string number, as it's a generalised string lookup, and as the same error number could have different textual messages, such as 26,"Type mismatch: expecting string" and 26,"Type mismatch: expecting number". I think API is something analagous to SYS "MessageTrans_Lookup","BASIC",47 TO A$:ERROR 26,A$ to get the 47th string and generate error number 26 with it.
I think I've seen one implementation where there are error messages internally as a table, eg, 4,"Mistake",5,"Missing ,",6,"Type mismatch", etc. but that's implementation-specific and not user-visible. Most implementations have the errors scattered around the code wherever they are generated, so there's no way to internally look them up anyway.
And then, there's no way to "look up" external errors (ERR>127) as they are external to the language, they could have come from anywhere, another module, a different ROM, a different processor, executed loaded code, executed inline code....
The closest is the Internationalisation module on RISC OS, where applications can use a Messages file to provide territory- and language-specific strings. But that's not indexed by error number, but by string number, as it's a generalised string lookup, and as the same error number could have different textual messages, such as 26,"Type mismatch: expecting string" and 26,"Type mismatch: expecting number". I think API is something analagous to SYS "MessageTrans_Lookup","BASIC",47 TO A$:ERROR 26,A$ to get the 47th string and generate error number 26 with it.
-
- Posts: 272
- Joined: Tue 18 Jun 2024, 09:32
Re: Error message from error number?
Thank you, that's what I thought but it's helpful to have your insight and additional detail.
Yes, my versions tend to do that but there's no legitimate way of accessing the table.I think I've seen one implementation where there are error messages internally as a table, eg, 4,"Mistake",5,"Missing ,",6,"Type mismatch", etc.
True, but in my versions it's only the error number, not the associated message, which is "scattered around", to avoid duplication of the string.Most implementations have the errors scattered around the code wherever they are generated, so there's no way to internally look them up anyway.
Ah, yes, I'd forgotten that Acorn BASICs have context-dependent error strings like that; mine don't. I can't see the logic of having an error number (ERR) which doesn't contain as much information as the associated string (REPORT$) does, for example it means it's practically impossible for error-handling code to report the error in a different language whilst retaining all the information.the same error number could have different textual messages, such as 26,"Type mismatch: expecting string" and 26,"Type mismatch: expecting number".