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

Unhandled exception catching on secondary threads.

P: n/a
I wish to make sure all unhandled exceptions (UE) are handled by a central
handler.
For primary thread UEs, this may be done by

string exceptionText;

AppDomain.CurrentDomain.UnhandledException +=
delegate(object sender, UnhandledExceptionEventArgs e)
{
exceptionText = e.ExceptionObject.ToString();
};

However, this does not work for UEs thrown from a secondary thread like the
timer object (not the forms control).

In this case, the secondary thread is not known until the timer event fires.

Any ideas please?
--
Mike Binks
Progressive Gaming Corp.
Apr 3 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
=?Utf-8?B?TWlrZSBCaW5rcw==?= <Mi*******@discussions.microsoft.com> wrote
in news:7E**********************************@microsof t.com:
I wish to make sure all unhandled exceptions (UE) are handled by a
central handler.


While I'm not sure this deals with your question directly, there is one
thing you need to keep in mind when using AppDomain.UnhandledException.

AppDomain.UnhandledException is NOT a "handler" for the exception - it is
just something that the framework uses to notify you that an exception has
occurred.

I dealt with a similar issue recently as I was developing some code for
handling plugins. The details depend on which version of .NET you are
running. If I remember correctly, the following applies:

In .NET 1.1, exceptions thrown on other threads die away without causing
the application to die.

In .NET 2.0, exceptions thrown on other threads will cause the application
to die.

See the following: (watch the URL wrap)

http://lab.msdn.microsoft.com/Produc...Feedback.aspx?
feedbackId=FDBK21092

A quote from the above URL: "As it turns out, the documentation of
UnhandledException is incorrect. (It's always been incorrect; I've filed a
bug to get it fixed.) The UnhandledException event handler is just a
notification that an exception has gone unhandled. Registering an event
handler does not actually handle the exception; it just handles the event."

-mdb

Apr 3 '06 #2

P: n/a
Hi,

Take a look at Application.ThreadException
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Mike Binks" <Mi*******@discussions.microsoft.com> wrote in message
news:7E**********************************@microsof t.com...
I wish to make sure all unhandled exceptions (UE) are handled by a central
handler.
For primary thread UEs, this may be done by

string exceptionText;

AppDomain.CurrentDomain.UnhandledException +=
delegate(object sender, UnhandledExceptionEventArgs e)
{
exceptionText = e.ExceptionObject.ToString();
};

However, this does not work for UEs thrown from a secondary thread like
the
timer object (not the forms control).

In this case, the secondary thread is not known until the timer event
fires.

Any ideas please?
--
Mike Binks
Progressive Gaming Corp.

Apr 3 '06 #3

P: n/a
Mike,
I recently put a lot of this information together in one place, so this
article

http://www.eggheadcafe.com/articles/20051205.asp

may be helpful. As Michael pointed out, AppDomain.UnhandledException
is NOT an "exception handler".
Cheers,
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Mike Binks" wrote:
I wish to make sure all unhandled exceptions (UE) are handled by a central
handler.
For primary thread UEs, this may be done by

string exceptionText;

AppDomain.CurrentDomain.UnhandledException +=
delegate(object sender, UnhandledExceptionEventArgs e)
{
exceptionText = e.ExceptionObject.ToString();
};

However, this does not work for UEs thrown from a secondary thread like the
timer object (not the forms control).

In this case, the secondary thread is not known until the timer event fires.

Any ideas please?
--
Mike Binks
Progressive Gaming Corp.

Apr 3 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.