Handle slicing exceptions when throwing
In the current code, the Handle class in art and gallery
can store an exception using a pointer with type
std::shared_ptr<cet::exception const>. The actual exceptions
that are built have type cet::coded_exception which
has cet::exception as a base class. To throw the
exception Handle uses "throw *whyFailed_;" which slices
the exception and throws an exception with the type of the
base class. In the current code, cet::exception has a virtual
function rethrow but it is private, coded_exception
does not override it, and Handle does not use it.
No users have reported the problem and its impact is
minor. If you try to catch the exception you must use
the base class type and the extra info which is originally
in the derived class has been sliced away so it is not
possible to access it.
There are different options available as to how to fix
#2 Updated by Christopher Green over 4 years ago
- Status changed from Assigned to Resolved
- Target version set to 2.00.01
- % Done changed from 0 to 100
- SSI Package - added
- SSI Package deleted (
The solution using
std::exception_ptr had the drawback that calling
std::make_exception_ptr() caused an exception throw and catch. Since it is our policy to avoid throwing exceptions as normal flow control, this was deemed unacceptable as a solution.
In addition to the aforementioned change, a couple of other cases of exceptions in non-exceptional circumstances were also removed, in commit art:fd42ce9.