Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No exception handling? #39

Open
pya opened this issue Jul 26, 2015 · 2 comments
Open

No exception handling? #39

pya opened this issue Jul 26, 2015 · 2 comments

Comments

@pya
Copy link
Contributor

pya commented Jul 26, 2015

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?

@i2y
Copy link
Owner

i2y commented Jul 26, 2015

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')

@pya
Copy link
Contributor Author

pya commented Jul 26, 2015

Ok. Good. Did not know this. Adding the as does th trick. Thanks for pointing this out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants