Reading a C ++ \ CLI Exception message in C #?

The following code throws an exception in C ++ and catch in C # C ++

throw std::exception ("a C++ exception"); 

When I catch in C #, it gives me the following:

 [SEHException (0x80004005): External component has thrown an exception.] 

this is what i call c ++ code

 using Foo.Bar.Sample; //C++ library .... Class1 class1 = new Class1(); //C++ class class1.throwAnException(); 

Just wondering how can I get a β€œC ++ exception” in C #

+6
c # exception exception-handling c ++ - cli
source share
3 answers

Did not ask the question correctly . This is an exception to C++\CLI not C++ . In C ++ \ CLI do the following:

  throw gcnew System::Exception("It is a C++\CLI exception"); 

and not C ++ native exception

Thank you all for your reply and comment.

+4
source share

I would recommend that you always break exceptions with the same runtime as theirs.

And the only way to analyze the exception is from C ++, since the layout of the exception is not defined.

+2
source share

As @CodeInChaos explained, C ++ and .NET have different modes of operation, so exceptions do not coexist very well.

Can you use C ++ / CLI for the C ++ part? This unifies the runtime, and exceptions will be compatible. Note that you may have a small portion of C ++ code that uses .NET (mixed mode).

+2
source share

All Articles