I have a C ++ library that is being called from a C # application using the C ++ / CLI cover library. In C ++ code, I want to throw an exception if something goes wrong. It is translated into SEHException in a managed world. However, the message containing the original exception naturally disappeared.
How to pass this message to C #?
- Can I somehow configure the translation so that, for example, it is
MyCppExceptionconverted to MyManagedExceptionby marching the message? - Is there any way to throw an exception so that the SEHException contains the message?
I want to avoid catching my exception in all functions of the C ++ / CLI shell and, if possible, rebuilding.
class MyException { const char* what() const { return "OH HI THERE"; } };
MyException e;
void throw_function()
{
throw e;
}
#include "cpp.h"
public ref class A
{
public:
static Throw() { throw_function(); }
}
public ref class E: public Exception
{
System::String^ GetMessage();
}
try
{
A.Throw()
}
catch (E e)
{
Console.WriteLine(e.GetMessage());
}
catch (SEHException seh)
{
Console.WriteLine(seh.Message);
}
source
share