ecole icon indicating copy to clipboard operation
ecole copied to clipboard

Allow for nested exceptions

Open gasse opened this issue 5 years ago • 6 comments

Replace Exception for std::exception in order to allow std::throw_with_nested. That would improve error messages for the users.

gasse avatar Feb 04 '20 21:02 gasse

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?

AntoinePrv avatar Feb 04 '20 21:02 AntoinePrv

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.

gasse avatar Feb 05 '20 17:02 gasse

So basically, we need to change all throws, 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?

AntoinePrv avatar Feb 06 '20 20:02 AntoinePrv

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.

gasse avatar Feb 06 '20 21:02 gasse

There is on open issue: https://github.com/pybind/pybind11/issues/1913

AntoinePrv avatar Feb 06 '20 22:02 AntoinePrv

Would be useful as well if Catch2 was able to unroll nested exceptions.

AntoinePrv avatar Apr 03 '20 23:04 AntoinePrv