catching unmanaged c++ exceptions

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

How do i catch an unmanaged c++ exceptions ?
right now i can catch the System.Runtime.InteropServices.SEHException and
System.Exception exceptions , but i wan't to catch myException unmanaged
class , how do i do this ?

Thanks.
 
Write a wrapper managed class for your C++ component. And create your own
exception class
Assume your unmanaged code contains a method like foo

void foo(){}

In wrapper class implement foo as ;
void foo()
{
try
{
//Call unmanaged foo here
}
catch(Exception ex)
{
throw new MyException(ex);
}
}

In all around your code you should handle only MyException for all unmanaged
exceptions...

HTH
 
How do i catch an unmanaged c++ exceptions ?

You can try a "general catch clause":

try
{
...
}
catch // nothing here
{
}

The language spec says it matches any exception type, but is slightly vague
on the details. Here is a quote:

"Some environments, especially those supporting multiple languages, might
support exceptions that are not representable as an object derived from
System.Exception, although such an exception could never be generated by C#
code. In such an environment, a general catch clause might be used to catch
such an exception. Thus, a general catch clause is semantically different
from one that specifies the type System.Exception, in that the former might
also catch exceptions from other languages."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top