QB64-Phoenix-Edition / QB64pe

The QB64 Phoenix Edition Repository
https://qb64phoenix.com
Other
124 stars 26 forks source link

Add _NEWHANDLER option for ON ERROR GOTO... #531

Closed RhoSigma-QB64 closed 1 month ago

RhoSigma-QB64 commented 1 month ago

This adds the _NEWHANDLER keyword to make a clear difference between existing legacy code and new QB64-PE specific code. It was required as the simple addition of a history chain to the legacy ON ERROR GOTO syntax introduced a potential memory leak to existing legacy code.

Now with _NEWHANDLER the possibility for this memory leak still exists and special care should be taken when using it, but at least existing code will not break anymore.

Legacy Syntax: ON ERROR GOTO {label|0}

Extended QB64-PE Syntax: ON ERROR GOTO [_LASTHANDLER|_NEWHANDLER label]

where the use of _NEWHANDLER will save the current handler to the history chain before actually setting the new handler, and _LASTHANDLER is used to restore back to the most recently saved handler. The use of the legacy ON ERROR GOTO 0 will also reset/clear all saved history entries.