nimpy icon indicating copy to clipboard operation
nimpy copied to clipboard

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

Open yuyamashiro opened this issue 3 years ago • 3 comments

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?

yuyamashiro avatar May 20 '21 15:05 yuyamashiro

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

qb-0 avatar Jul 23 '22 22:07 qb-0

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 avatar Nov 01 '23 20:11 PaarthShah

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

PaarthShah avatar Jan 14 '24 05:01 PaarthShah