-
Notifications
You must be signed in to change notification settings - Fork 29
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
Exception support #7
Comments
Good question ! |
Ok, I see. I have tried it by adding %include "std_except.i" And manually adding the %catches(std::runtime_error) MyLib::my_method(); It works on Python and map to a But I was wondering if there is another method. |
According to the doc
|
Yes, but Exception specification is deprecated since C++11 and removed in C++17.
So `%catches` seems like the only choice.
17 juin 2020 19:58:16 Mizux <[email protected]>:
… According to the doc[http://www.swig.org/Doc4.0/SWIGDocumentation.html#SWIGPlus_exception_specifications]
> Exceptions are automatically handled for methods with an exception specification. Similar handling can be achieved for methods without exception specifications through the %catches feature.
>
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub[#7 (comment)], or unsubscribe[https://github.com/notifications/unsubscribe-auth/ACDPSYGVWDDP7U25QFXDRYDRXD73RANCNFSM4OAVPB7A]. [https://github.com/notifications/beacon/ACDPSYDPKDQ2CL7UK3XGKCLRXD73RA5CNFSM4OAVPB7KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEZ476OQ.gif]
|
looking at the swig code: swig should be able to catch most standard exceptions hope to play with it soon ! e.g. adding in C++ Foo class a method: void letsThrow(int idx) {
switch (idx) {
case 1:
throw std::runtime_error("runtime error");
case 2:
...
}
} and in foo.i %include exception.i
%exception {
try {
$action
}
SWIG_CATCH_STDEXCEPT // catch std::exception
catch (...) {
SWIG_exception_fail(SWIG_UnknownError, "Unknown exception");
}
}
%feature("except")
foo::letsThrow(int); and see what's happen 😄 when called from Python/Java/.Net |
Oh, this snippet seems great! It avoids to declare a %feature("except") |
Thank you for this nice work!
I was wondering if you ever tried to propagate exceptions from C++ to the other languages?
This may be added to this example.
The text was updated successfully, but these errors were encountered: