yglukhov / nimpy

Nim - Python bridge
MIT License
1.47k stars 62 forks source link

How do I catch (nimpy.KeyError) in Python? #207

Open yuyamashiro opened 3 years ago

yuyamashiro commented 3 years ago

I want to except nimpy.KeyError. However I can't do it.

Example:

try:
        # Some code: call Nim by nimpy
    except KeyError as e:
        # I  can't catch nimpy.KeyError
        print("key error")
        print(e, type(e))
    except Exception as e:
        print("Unknown")
        print(e, type(e))
        raise e

Output

Unknown
Unexpected error encountered: key not found: city <class 'nimpy.KeyError'>
nimpy.KeyError: ...

How do I catch nimpy.KeyError?

qb-0 commented 2 years ago

I'm also interested how nimpy exceptions can be catched. Or how Python Exceptions could be raised from nim.

PaarthShah commented 10 months ago

This is a very old issue, but it's affecting me too, and I think I have a way to fix nimpy to raise native python exceptions when possible.

PaarthShah commented 7 months ago

Made a PR for this: https://github.com/yglukhov/nimpy/pull/300