Updated December 2012; see History
The ERR(#) function was part of the original A-BASIC, but A-Shell adds the new sub-functions, ERR(7,8,9). For completeness, all the sub-functions are documented in the following table:
Sub-Function |
Description |
ERR(0) |
Returns the last Basic error code. See sys:errmsg.xxx for the description of all the Basic error codes. Also see ERRMSG.SBR for info on displaying and/or logging the error text under application control, as well as .LINENO in the Dot Variables table. |
ERR(1) |
Returns the last line number processed. Note that since A-Shell Basic doesn't require line numbers on every line, the last line number processed might be a long way from where the error occurred (or it may be 0 if the program has no line numbers). See ERR(8) to get the precise location of the error. |
ERR(2) |
Returns the last file channel processed. See FILNAM.SBR for info on retrieving the name of the file associated with the channel. |
ERR(7) |
(A-Shell Extension) Reports the location of the last error within the current stack frame/scope. This would differ from ERR(8) if the error occurred within a function or procedure and was allowed to percolate up to a higher level, where ERR(7) would indicate the line that called the function or procedure. Also see .LOCATION in the Dot Variables table to retrieve the current location counter outside the context of a BASIC error. |
ERR(8) |
(A-Shell Extension) Returns the internal location counter where the error occurred. Note that by convention, location counter values are usually displayed in hex, but the Basic PRINT statement has no way to know (or support) this. So if you are going to print the value of err(8), you may want to use MIAMEX, MX_OCVT, or the Fn'Dec2Hex$() function (in the SOSLIB). To match the location with a line of source code, you'll need to compile your program with the /L switch to create a LSX file, which lists the location counter (in hex) for each statement. Also see .LOCATION in the Dot Variables table to retrieve the current location counter outside the context of a BASIC error. |
ERR(9) |
(A-Shell Extension) Returns the function or procedure nesting level at the time of the error (equivalent to the dot variable .NEST_LEVEL). This might be helpful in debugging. |
If you add TRACE=BASERR to miame.ini (highly recommended), then all BASIC errors will be logged to the ashlog.log file, including most of the above information, and indicating whether the error was trapped. Also see Call Stack Tracing.
Errors occurring within User-defined Functions or Procedures will appear to the calling routine to have occurred on the line in which the Function or Procedure was invoked, unless the Function/Procedure performs its own local error trapping.
History
2012 December, A-Shell 6.1.1329: ERR(7) added, meaning of ERR(8) restored to original (as documented above)