By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,424 Members | 1,402 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,424 IT Pros & Developers. It's quick & easy.

Unmanaged exception caught how in managed code?

P: n/a
Suppose the following:

// Unmanaged code
class UnmanagedException /* not visible outside of unmanaged code */
{
};
void DoSomething() /* visible (exported) to managed code */
{
throw new UnmangedException();
}

// Managed code
// Call into unmanaged code
try
{
DoSomething();
}
catch (???)
{
}
What is/are suitable types to catch in the managed code?

I see SEHException and its parent ExternalException, but these (automatic)
wrappers seem to be based on COM hresult types of exceptions.

My understanding is that the managed framework automatically catches,
repackages, and rethrows the unmanaged exception, but as what?

Thanks

--
Bret Pehrson
mailto:br**@infowest.com
NOSPAM - Include this key in all e-mail correspondence <<38952rglkwdsl>>
Nov 15 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hello Bret,

Thanks for posting in the group.

I noticed that you posted the same question in dotnet.languages.vc group
and have replied you there. If you have time, please check my reply there.
If there is anything unclear, please feel free to post in that group and we
will follow up you there.

Have a good day.

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! C www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 15 '05 #2

P: n/a
Hi Bret,
You can catch unmanaged exception in c# but you can't use them. you can only
rethrow them

if you have try/catch block like this
try
{
....
}
catch
{
...
throw;
}

the catch block will catch all exceptions (managed and unmanaged) and the
*thow* operator will rethrow catched exception *AS IS*.

This is the only way you can catch unmanaged exception with try/catch block
in c# and your choices are either to swallow it or rethrow it.

--
B\rgds
100
"Bret Pehrson" <br**@infowest.com> wrote in message
news:40***************@infowest.com...
Suppose the following:

// Unmanaged code
class UnmanagedException /* not visible outside of unmanaged code */
{
};
void DoSomething() /* visible (exported) to managed code */
{
throw new UnmangedException();
}

// Managed code
// Call into unmanaged code
try
{
DoSomething();
}
catch (???)
{
}
What is/are suitable types to catch in the managed code?

I see SEHException and its parent ExternalException, but these (automatic)
wrappers seem to be based on COM hresult types of exceptions.

My understanding is that the managed framework automatically catches,
repackages, and rethrows the unmanaged exception, but as what?

Thanks

--
Bret Pehrson
mailto:br**@infowest.com
NOSPAM - Include this key in all e-mail correspondence <<38952rglkwdsl>>

Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.