Added modern exception -based error system for Stroll#10
Merged
Conversation
Author
|
I hope You will merge this to your main branch, If there is no conflict please merge it I need it for my college! |
Collaborator
|
Thank you 🙏 I appreciate your effort! I hope you get good scores and grades! |
Author
|
Thanks mate!!! If i have more time I will contribute more to your project! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
PR Description
This PR improves the error-handling system in Stroll by introducing real Python exception classes while keeping the old error objects intact for backward compatibility.
What I changed
Added a new StrollError base class that inherits from Python’s Exception.
Added specific exception subclasses like SyntaxErrorStroll, RuntimeErrorStroll, TypeErrorStroll, etc.
Added optional support for line, column, filename, and token information inside errors.
Added a raise_syntax() helper function to simplify throwing syntax errors from the parser.
Kept the old classes (Syntaxerror, Miscerror, Extensionerror) and terminate() to avoid breaking existing interpreter code.
Why I made these changes
The previous error classes were not real exceptions, so they couldn’t be raised or caught properly.
You used os._exit(1) which immediately kills execution, making the REPL and debugging difficult.
Adding structured exceptions lays the groundwork for better error messages, safer parsing, and a more reliable runtime.
Keeping the legacy system allows the project to transition gradually without breaking anything.
Benefits
You can handle errors more cleanly in the future (especially in the REPL).
Parser and runtime will be able to throw detailed errors with line/column info.
This makes future improvements (like better syntax errors, stack traces, and testing) much easier.
No breaking changes — existing code still works exactly the same.