Add _NEWHANDLER option for ON ERROR GOTO... #531
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.