I want to call a function that can throw an exception. If it throws an exception, I want to catch it and pass the exception object to the handler function. By default, the implementation of a handler function is just an exception. Below is the code with reduced code to illustrate the problem:
struct base_exception : exception { char const* what() const throw() { return "base_exception"; } }; struct derived_exception : base_exception { char const* what() const throw() { return "derived_exception"; } }; void exception_handler( base_exception const &e ) { throw e;
However, throw e in exception_handler() returns a copy of the static type of the exception, i.e. base_exception . How can I make exception_handler() throw an actual exception that has the correct type of runtime derived_exception ? Or how can I redo things to get what I want?
source share