You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm wrapping a library which throws exceptions not derived from std::exception. It would be nice to take advantage of cxx's automatic C++ try/catch and conversion to a rust Result<T, cxx:Exception>, but it looks like currently only std::exception is caught.
Relatedly, I think it would be useful to have more control over the rust Error type in the automatic conversion. For example, perhaps the user might want to define different error variants which are returned based on runtime behavior.
I don't have specific suggestions for how to deal with these issues, but I wanted to raise them.
The text was updated successfully, but these errors were encountered:
This is already supported (but not yet documented; cc #179) by providing a rust::behavior::trycatch function template with the right signature in one of your headers included by the cxx::bridge block. https://github.com/dtolnay/cxx/pull/285/files shows a complete compilable example. I put it as a separate header there in case you would want to reuse the same catch logic in multiple Rust modules, but you could alternatively put the same thing directly in the existing header instead.
Thank you so much, there's no way I would have found that without your help, despite looking into the code for a while.
The example doesn't quite compile for me. MS C++ compiler tells me error C2429: language feature 'nested-namespace-definition' requires compiler flag '/std:c++17' and fixed this by changing namespace rust::behavior { to namespace rust { namespace behavior {.
I'm wrapping a library which throws exceptions not derived from
std::exception
. It would be nice to take advantage of cxx's automatic C++ try/catch and conversion to a rustResult<T, cxx:Exception>
, but it looks like currently onlystd::exception
is caught.Relatedly, I think it would be useful to have more control over the rust Error type in the automatic conversion. For example, perhaps the user might want to define different error variants which are returned based on runtime behavior.
I don't have specific suggestions for how to deal with these issues, but I wanted to raise them.
The text was updated successfully, but these errors were encountered: