Hi popopo!
Im sorry my manuals are so obtuse! I will try harder to make them clearer.
ERRM$ doesnt 'catch' anything. It simply returns the message associated with a given error code as a string. Then you can format the error message as you like, print it where you like, etc. You cant do that so easily with REPORT.
You, or your program, have to provide the error code by other means, for example:
PRINT ERRM$(-10)
Prints "End of file" or equivalent depending on your OSes language setting.
Or
Code: Select all
100 INPUT#0; 'Enter a file name'! fnm$
110 er = FTEST(fnm$)
120 IF er < 0 THEN
130 PRINT#0; 'Testing'! fnm$; ': Error ';
140 INK#0; 2: PRINT#0; ERRM$(er): INK#0; 4
150 END IF
Getting to the message tables: I wrote this so long ago, that I cant remember the details off the top off my head; the source code is there for your perusal! Otherwise I refer you to the SMSQ/E Reference Guide.
Basically, SMSQ/E has a method for getting the message tables; in Qdos you have to fiddle it out. Thats why there are two versions of the toolkit, one universal, and a more compact and sane version for SMSQ/E only.
You can also construct your own ad hoc messages. It works for any language, including BASIC, and works with all QL OSes. Simply poke the message string into some safe memory and return the address of the message with the top bit set. The function below does that. It is a bit convoluted, mainly in order to make it universal and easier to understand(!)
Code: Select all
10 er = MakeErr("This is an error!")
20 PRINT ERRM$(er): rem Requires my ERRM toolkit
30 REPORT er: rem This one doesnt, only TK2
40 CLCHP
50 :
100 DEFine FuNction MakeErr(msg$)
110 LOCal i, l%, el%, a, m$, b$(32)
120 m$ = msg$ & CHR$(10): REMark Termination EOL
130 l% = LEN(m$)
140 el% = (l% + 3) && -2: REMark Make even
150 a = ALCHP(el%)
160 POKE_W a, l%: REMark String length
170 :
180 REMark Enter error message:
190 FOR i = 1 TO l%: POKE a + i + 1, m$(i)
200 b$ = BIN$(a, 32): b$(1) = '1': REMark Set top bit
210 RETurn BIN(b$): REMark Return error "code"
220 END DEFine MakeErr
230 :
240 :