-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
pybind breaks exception handling #1272
Comments
This is most likely caused by Try, as a quick test, adding class PYBIND11_EXPORT unsuitable_error : public std::logic_error { ... } or if including class __attribute__ ((visibility("default"))) unsuitable_error : public std::logic_error { ... } If that fixes it, then it's definitely identified the issue. From there, it's a matter of figuring out how to solve it (without needing to change the foreign header). A couple ideas to try (I haven't tested these):
class PYBIND11_EXPORT unsuitable_error;
#include <whatever.h>
|
@jagerman That indeed fixes it! Both workarounds you propose work. Is there anything specific that makes my exception class problematic (compared to the stdexcept classes for example), or is this is a generic issue that more people are likely to hit? |
Actually, the part about |
Adding |
Oh, that probably should be |
Yeah, it's a property set on the module target set up by |
If I remember correctly, this doesn't affect stdlibc++ (at least for non-ancient versions), but does affect libc++ (are you on macOS, by any chance? Or on Linux using clang with libc++?). But no, there isn't anything specific to your class: pybind has to deal with the same issue internally for exception class wrappers that we use by registering one exception handler for each module: pybind11/include/pybind11/detail/internals.h Lines 146 to 160 in 2d0507d
|
I am indeed on macOS. |
When compiling with -fvisibility=hidden, there are issues with pybind11's exception translator [1], because libc++ in particular considers the two different includes different symbols. This is resolved by using the symbol visibility mechanism, which is useful for the C API anyway. [1] pybind/pybind11#1272
When compiling with -fvisibility=hidden, there are issues with pybind11's exception translator [1], because libc++ in particular considers the two different includes different symbols. This is resolved by using the symbol visibility mechanism, which is useful for the C API anyway. [1] pybind/pybind11#1272
When compiling with -fvisibility=hidden, there are issues with pybind11's exception translator [1], because libc++ in particular considers the two different includes different symbols. This is resolved by using the symbol visibility mechanism, which is useful for the C API anyway. [1] pybind/pybind11#1272
This issue seems resolved. |
dlisio needs to explicitly make it's custom exceptions visible in order for pybind to pick them up correctly. As this is due to an issue with pybind11 [1], prefer using pybinds export macro in core.cpp over fixing it with our own visibility symbol DLISIO_API. [1] pybind/pybind11#1272
dlisio needs to explicitly make it's custom exceptions visible in order for pybind to pick them up correctly. As this is due to an issue with pybind11 [1], prefer using pybinds export macro in core.cpp over fixing it with our own visibility symbol DLISIO_API. [1] pybind/pybind11#1272
I've spent many hours today trying to figure out why my exception handling does not work. I have a C++ library which raises an exception in its own namespace:
stylist::unsuitable_error
. Catching this error works perfectly within that library. In my wrapper code it fails. The exception is defined like this:I have some code which tries to handle that exception being thrown:
This works perfectly in a standalone program:
However, the exact same code in pybind11 breaks. The wrapper code is simple enough:
and running that results in:
The standalone tool and Python wrapper are compiled from the same CMake config:
The text was updated successfully, but these errors were encountered: