User Tools

Site Tools


displaying_20program_20errors_20in_20a_20message_20box

Displaying program errors in a message box

by Jon Ripley, July 2006

To display a program error in a message box use code similar to the following:

        ON ERROR SYS "MessageBox", @hwnd%, REPORT$ + " at line " + STR$ERL, "Error", 48:QUIT


If you replace ““Error”” by zero the result will be the same, except on non-English versions of Windows when the appropriate foreign language equivalent of Error will be used:

        ON ERROR SYS "MessageBox", @hwnd%, REPORT$ + " at line " + STR$ERL, 0, 48:QUIT


For more complex error reporting or if you have a dedicated error handler you can place the above code in a procedure. To do this use code similar to the following at the start of your program:

        ON ERROR PROC_reporterror:QUIT

Here we call PROC_reporterror and terminate the program.

For unreleased programs use code similar to the following:

        DEF PROC_reporterror
        SYS "MessageBox", @hwnd%, REPORT$ + " at line " + STR$ERL, 0, 48
        ENDPROC


For released programs, it is often wise to give users more information with error reports. Asking the user to contact you with sufficient information for you to correct the error is a good idea.

To do this use code similar to the following:

        DEF PROC_reporterror
        LOCAL msg$, @%
        msg$ = REPORT$
        IF ERL msg$ += " at line " + STR$ERL
        SYS "MessageBox", @hwnd%, msg$ + CHR$13 + CHR$13 + \
        \ "Please contact the program author stating details" + CHR$13 + \
        \ "of this error and how to reproduce it.", \
        \ "An error has occurred", 48
        ENDPROC

Change the text of the error report to suit your needs; for instance, you might want to include a contact email address.

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
displaying_20program_20errors_20in_20a_20message_20box.txt · Last modified: 2024/01/05 00:22 by 127.0.0.1