0

I am trying to use Boost exceptions for the additional metadata that I can attach to exceptions as they bubble up the call stack. But one use case I have encountered but do not know how to handle is: how do I catch a std::exception and wrap that with a boost exception and throw/rethrow the wrapped exception? For example:

try {
    CallFunctionThatThrowsStdException();
} catch(std::exception& ex) {
    MyBoostException bex{ex};
    bex << "Add metadata for this call scenario";
    throw bex;
}

What is a good open source project that uses Boost.Exception to study?

Thanks!

Phil
  • 5,822
  • 2
  • 31
  • 60
  • Why do you want to wrap a `std::exception`? Why not copy data (e.g. the result of its `what()` member function) from the `std::exception` into the metadata of the boot exception? – Peter Aug 11 '20 at 02:43
  • 1
    Well, at the least I would like to capture the exception type in addition to the ``what()`` string. But some exceptions contain more than just the what string, so I was being idealistic in hoping that I could simply wrap the entire exception. – Phil Aug 11 '20 at 03:16

0 Answers0