-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Catching specific exception types via error_already_set #700
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
Comments
This commit adds `error_already_set::matches()` convenience method to check if the exception trapped by `error_already_set` matches a given Python exception type. This will address #700 by providing a less verbose way to check exceptions.
@llchan It's mentioned in the API reference for error_already_set. |
I see, looks good, but I was thinking we could also add something in the tutorial-ish section here: |
Ah, right, it does seem like that section is overwhelmingly about C++ -> Python exception translation, but not the other way around. If you have something in mind for it, would you be willing to submit a PR? |
If I want to perform the C++ equivalent of this python code:
I can do it like this, but it's rather verbose:
Is there a more idiomatic way to do this? If not, could we modify the type hierarchy and/or the
error_already_set
mechanism to allow for something closer to this?The text was updated successfully, but these errors were encountered: