feat: improve error handling in interpreter
Introduced better error handling in the Deuthon interpreter loop by wrapping the code execution in a try-except block to catch and print exceptions using `traceback`. This change also updates the interpreter to only print output when `eval` returns a non-None result, enhancing usability and feedback for the user. The addition of `traceback` provides users with more insightful error messages, helping to debug incorrect German code inputs more effectively.
This commit is contained in:
parent
3f9f941c7a
commit
3933ce4736
1 changed files with 11 additions and 3 deletions
|
@ -1,11 +1,19 @@
|
|||
from .transformer import parse_german_code
|
||||
|
||||
import traceback
|
||||
|
||||
def interpreter():
|
||||
while True:
|
||||
try:
|
||||
german_code = input('>>> ')
|
||||
german_code = input(">>> ")
|
||||
except EOFError:
|
||||
break
|
||||
|
||||
try:
|
||||
python_code = parse_german_code(german_code)
|
||||
exec(python_code)
|
||||
result = eval(python_code, globals())
|
||||
|
||||
if result is not None:
|
||||
print(result)
|
||||
except Exception:
|
||||
print(traceback.format_exc())
|
||||
|
|
Loading…
Reference in a new issue