exceptions

D

dragonslayer008

I read in a C++/CLI book that:

"In C++/CLI, exceptions are always thrown on the managed heap, never
the stack."

So I'm wondering if this will be a problem for me. Here is my
situation.

I am using C++/CLI mainly to wrap some unmanaged C++ code so the code
can be used from C# via a DLL. My unmanaged code can throw some
exceptions (unmanaged exception class).

My question is, can the methods of the managed class try and catch the
unmanaged exceptions? That is, could I write something like this in a
managed class method:

try
{
native->foo();
}
catch( NativeException e)
{
...
}

If not, I guess I need to move the native exception handling down into
the unmanaged classes?
 
D

Doug Semler

I read in a C++/CLI book that:

"In C++/CLI, exceptions are always thrown on the managed heap, never
the stack."

So I'm wondering if this will be a problem for me. Here is my
situation.

I am using C++/CLI mainly to wrap some unmanaged C++ code so the code
can be used from C# via a DLL. My unmanaged code can throw some
exceptions (unmanaged exception class).

My question is, can the methods of the managed class try and catch the
unmanaged exceptions? That is, could I write something like this in a
managed class method:

try
{
native->foo();
}
catch( NativeException e)
{
...
}

If not, I guess I need to move the native exception handling down into
the unmanaged classes?


AFAIK, all exceptions (both SEH and C++) are wrapped into a "generic"
SEHException class that can be caught in managed code. I do not know that
you can get the type (or any of the contents) of the unmanaged exception
type that was thrown from the unmanaged code...but I believe there's a way
to get at least the value if it's an SEH exception type.

I'm pretty sure there's a bunch of information in MSDN on SEH exceptions and
how they're handled in managed code...

--
Doug Semler, MCPD
a.a. #705, BAAWA. EAC Guardian of the Horn of the IPU (pbuhh).
The answer is 42; DNRC o-
Gur Hfrarg unf orpbzr fb shyy bs penc gurfr qnlf, abbar rira
erpbtavmrf fvzcyr guvatf yvxr ebg13 nalzber. Fnq, vfa'g vg?
 

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

Top