ecole
ecole copied to clipboard
Allow for nested exceptions
Replace Exception
for std::exception
in order to allow std::throw_with_nested
. That would improve error messages for the users.
Exceptions inherit from std::exception
, I think that should be the way to be.
https://github.com/ds4dm/ecole/blob/fa62396dc424ea9be1d636b7e07a8905f7f06d91/libecole/include/ecole/exception.hpp#L9
std::throw_with_nested
seems to be templated by any type also.
What are you trying to achieve?
You would like to change throw
statements with std::throw_with_nested
?
Good, I had not realized that !
Typically I want to be able to catch an exception triggered from SCIP, and add more information / context to it. Say, I am trying to access a SCIP parameter, and a SCIP Exception is thrown: SCIP_RETCODE -12: The parameter with the given name was not found.
Then I would like to re-throw the Exception but indicate the name of the parameter that was accessed. I guess std::throw_with_nested
is what I want in this situation.
So basically, we need to change all throw
s, to std::throw_with_nested
.
In the example of the std doc, it seems special care is needed then to print them.
Is this something by automtically when an uncaught exception causes the program to terminate?
Or done automatically by pybind?
In my last experiments it seems pybind does not process nested exceptions the way I want, as it only prints the lastly thrown exception... Maybe not the way to go then.
There is on open issue: https://github.com/pybind/pybind11/issues/1913
Would be useful as well if Catch2 was able to unroll nested exceptions.