Wrap std :: exception and ApplicationException

I have the following code in the C ++ / CLI library to catch unmanaged exceptions and throw them away:

catch(const std::exception &e)
{
    String ^errorMessage = String::Format(L"Parser threw exception: {0}", gcnew String(e.what()));
    throw gcnew ApplicationException(errorMessage);
}

Is this the best way? I seem to be losing a lot of information.

+3
source share
1 answer

I assume that you mean that you throw away the derived type and any data that it stores. You cannot do this as a general solution. Of course, if you use the Foo library, and it often raises a FooError, you can catch (const FooError& e)also handle it on purpose.

You can also use RTTI to detect the type of runtime of the exception and add this to the exception. Net. The name that appears is somewhat ugly.

+3

Source: https://habr.com/ru/post/1726171/


All Articles