ERRORMESSAGE$: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
m (Protected "ERRORMESSAGE$" ([Edit=Allow only autoconfirmed users] (indefinite) [Move=Allow only autoconfirmed users] (indefinite)))
No edit summary
 
(7 intermediate revisions by the same user not shown)
Line 11: Line 11:
* Used in program error troubleshooting.
* Used in program error troubleshooting.
* The message returned is identical to the message shown in the dialog box that appears if your program has no error handler. See [[ERROR Codes]] for the full list of error codes and their messages.
* The message returned is identical to the message shown in the dialog box that appears if your program has no error handler. See [[ERROR Codes]] for the full list of error codes and their messages.


{{PageExamples}}
{{PageExamples}}
''Example 1:'' Using an error handler that ignores any error.
''Example 1:'' Using an error handler that ignores any error.
{{CodeStart}}
{{Cl|ON ERROR}} {{Cl|GOTO}} Errhandler
{{Text|<nowiki>' Main module program error simulation code</nowiki>|#919191}}
{{Cl|ERROR}} {{Text|7|#F580B1}} {{Text|<nowiki>' simulate an Out of Memory Error</nowiki>|#919191}}
{{Cl|PRINT}} {{Text|<nowiki>"Error handled...ending program"</nowiki>|#FFB100}}
{{Cl|SLEEP}} {{Text|4|#F580B1}}
{{Cl|SYSTEM}} {{Text|<nowiki>' end of program code</nowiki>|#919191}}


{{CodeStart}} '' ''
Errhandler: {{Text|<nowiki>' error handler sub program line label</nowiki>|#919191}}
{{Cl|ON ERROR}} {{Cl|GOTO}} Errhandler
{{Cl|PRINT}} {{Text|<nowiki>"Error"</nowiki>|#FFB100}}; {{Cl|ERR}}; {{Text|<nowiki>"on program file line"</nowiki>|#FFB100}}; {{Cl|_ERRORLINE}}
  ' Main module program error simulation code
{{Cl|PRINT}} {{Text|<nowiki>"Description: "</nowiki>|#FFB100}}; {{Cl|_ERRORMESSAGE$}}; {{Text|<nowiki>"."</nowiki>|#FFB100}}
{{Cl|ERROR}} 7          ' simulate an Out of Memory Error
{{Cl|BEEP}} {{Text|<nowiki>' warning beep</nowiki>|#919191}}
PRINT "Error handled...ending program"
{{Cl|RESUME}} {{Cl|NEXT}} {{Text|<nowiki>' moves program to code following the error.</nowiki>|#919191}}
{{Cl|SLEEP}} 4
{{Cl|SYSTEM}}           ' end of program code
 
Errhandler:              'error handler sub program line label
  PRINT "Error"; {{Cl|ERR}}; "on program file line"; {{Cl|_ERRORLINE}}
  PRINT "Description: "; {{Cl|_ERRORMESSAGE$}}; "."
  {{Cl|BEEP}}             ' warning beep
{{Cl|RESUME}} NEXT       ' moves program to code following the error. '' ''
{{CodeEnd}}
{{CodeEnd}}



Latest revision as of 21:20, 28 March 2023

The _ERRORMESSAGE$ function returns a human-readable description of the most recent runtime error, or the description of an arbitrary error code passed to it.


Syntax

e$ = _ERRORMESSAGE$
e$ = _ERRORMESSAGE$(errorCode%)


Description

  • Used in program error troubleshooting.
  • The message returned is identical to the message shown in the dialog box that appears if your program has no error handler. See ERROR Codes for the full list of error codes and their messages.


Examples

Example 1: Using an error handler that ignores any error.

ON ERROR GOTO Errhandler
' Main module program error simulation code
ERROR 7 ' simulate an Out of Memory Error
PRINT "Error handled...ending program"
SLEEP 4
SYSTEM ' end of program code

Errhandler: ' error handler sub program line label
PRINT "Error"; ERR; "on program file line"; _ERRORLINE
PRINT "Description: "; _ERRORMESSAGE$; "."
BEEP ' warning beep
RESUME NEXT ' moves program to code following the error.


See also



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link