[Tip/Trick] Error Listener - Forum

Forum Navigation
Climate strike banner
You need to log in to create posts and topics.

[Tip/Trick] Error Listener

I have made an error listener for VisualNeo Win. Of course, you can just enable Show error messages in:
Book > Book Properties > Access
But making your own error message listener gives you more control on how errors are handled.
For example, you can ask the user to quit or continue if an error happens and even stop all things that may cause the program to freeze because whatever it depended on it returned the error. You can even invoke errors directly via

SetVar "[LastError]" "Failed to do something."

Here's how to do it:
1.) Go to Book > Book Properties > Access and uncheck "Show error messages".
2.) Place a Timer object in the Master Page (make sure your page has Show items from master page checked)
3.) For the Timer's properties, check Stop timer when leaving page (this is so it stops automatically when the program is closed) and set Timer interval (milliseconds) to 100 then put GoSub "OnError" for the Timer's Timer Interval event code.
4.) Go to Book > Subroutines > New... and put OnError as the Subroutine name.
5.) For the OnError subroutine code put this (comments for explanation):

.Check if the [LastError] VisualNeoWin variable contains something by checking its length
.Store [LastError]'s length into a variable
StrLen "[LastError]" "[Length_RET1]"
.Check if the length of the variable is not empty (greater than 0)
If "[Length_RET1]" ">" "0"
.An error occurred, do something such as showing an error message in a dialog
Alert "Error" "[LastError]"
.Reset the [LastError] variable to prevent this method from happening over and over again repeatedly
SetVar "[LastError]" ""


I have updated this post from @xchellx.
Thank you very much!!