mochi
mochi copied to clipboard
No exception handling?
There are exceptions:
>>> 1 / 0
Traceback (most recent call last):
... site-packages/mochi/core/main.py", line 120, in interact
eval_tokens(tokens)
.../site-packages/mochi/core/builtins.py", line 1008, in eval_tokens
exec(code, global_env)
File "<string>", line 1, in <module>
ZeroDivisionError: division by zero
But there seems to be no way to catch them:
>>> try:
... 1 / 0
... except:
... print('got it')
...
ParsingError: file=<string> lineno=3 colno=7
How would an exception in Mochi be handled?
Currently, Mochi supports only try-except-as statement. It's enough for me so far. https://github.com/i2y/mochi/blob/master/mochi/parser/parser.py#L306
try:
1/0
except Exception as e:
print('got it')
Ok. Good. Did not know this. Adding the as does th trick. Thanks for pointing this out.