08-16-2024, 07:51 PM
Right, you can use ON ERROR inside SU/FUNC to designate another handler, but the handler label must be in the main part of the program.
I like that behavior, as it provides an easy mechanism to cleanly emergency exit your program. I use this a lot in my GuiTools Framework:
The SUB InternalErrHandler switches to an simple internal trap handler just saving the error for later flow control, SUB UserErrHandler switches back to the regular user handler with message box popup.
More than that I've an "IF _EXIT THEN ERROR 1000" in every essential loop, so when the user closes the program in a sudden unexpected moment, then ERROR 1000 jumps directly into the active error handler no worries about how deep in the SUB/FUNC calling stack or nested loops the program is right now. The error handlers notice error number 1000 as immediate exit request and RESUME to the label "emergencyExit:" where a proper cleanup procedure is done before the program finally ends with SYSTEM.
I like that behavior, as it provides an easy mechanism to cleanly emergency exit your program. I use this a lot in my GuiTools Framework:
The SUB InternalErrHandler switches to an simple internal trap handler just saving the error for later flow control, SUB UserErrHandler switches back to the regular user handler with message box popup.
More than that I've an "IF _EXIT THEN ERROR 1000" in every essential loop, so when the user closes the program in a sudden unexpected moment, then ERROR 1000 jumps directly into the active error handler no worries about how deep in the SUB/FUNC calling stack or nested loops the program is right now. The error handlers notice error number 1000 as immediate exit request and RESUME to the label "emergencyExit:" where a proper cleanup procedure is done before the program finally ends with SYSTEM.
GuiTools, Blankers & other Projects:
https://qb64phoenix.com/forum/forumdisplay.php?fid=32
Libraries & useful Functions:
https://qb64phoenix.com/forum/forumdisplay.php?fid=23
https://qb64phoenix.com/forum/forumdisplay.php?fid=32
Libraries & useful Functions:
https://qb64phoenix.com/forum/forumdisplay.php?fid=23