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:
Kumi 2024-05-23 14:39:57 +02:00
parent 3f9f941c7a
commit 3933ce4736
Signed by: kumi
GPG key ID: ECBCC9082395383F

View file

@ -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())