471,627 Members | 1,716 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,627 software developers and data experts.

Global Catching of All Unhandled Exceptions

Hello. I was wondering if its possible? Basically my program has a ThreadPool and that ThreadPool
works on many different methods. Its very important to me that no pop up's ever occur; I have a
"try/catch" block around my main but any exception that the ThreadPool creates crash's the
application (and produces a pop up). ((For example Java has the "unhandledException(...)" method in
the "ThreadGroup" class that you can simply override)). Does C# have something like this?

Things I've Tried:
http://msdn.microsoft.com/library/de...l=/library/en-
us/cpref/html/frlrfsystemwindowsformsapplicationclassthreadexcep tiontopic.asp

This has almost exactly what I wanted (I thought...). I add the following to my main (and the
class)

CustomExceptionHandler eh = new CustomExceptionHandler();
Application.ThreadException += new ThreadExceptionEventHandler(eh.OnThreadException);

internal class CustomExceptionHandler {
public void OnThreadException(object sender, ThreadExceptionEventArgs t) {
MessageBox.Show("IsThisWorking?");
Application.Exit();
}
}

But then I have the ThreadPool invoke a method that simply throws an excpetion and it still crash's
my program... No MessageBox is shown either. Can someone tell me what I'm missing?
Some more information: Basically I know I can put "try/catch" blocks around all the methods that
the ThreadPool can invoke on but it just seems ugly and theres a lot of methods (this is what I am
currently doing). Also I don't care if I can post any messages to the user or anything when an
uncaught exception occures (simply having the application exit would be great so if there's a way
for my program to just disable the "XXXX has encountered a problem and needs to close. We are sorry
for the inconvenience." Then that would also be a great solution for me if someone knows how I can
set my program to do that...
Best Regards,
Never Best
--
----------------------------------------------
Posted with NewsLeecher v3.0 Final
* Binary Usenet Leeching Made Easy
* http://www.newsleecher.com/?usenet
----------------------------------------------
Dec 20 '05 #1
1 1940
Hi,

Sure do, you can use Application.ThreadException or
AppDomain.UnHandledExeption
Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"NvrBst" <Nv****@hotmail.com> wrote in message
news:11*****************************************@r oc.usenetexchange.com...
Hello. I was wondering if its possible? Basically my program has a
ThreadPool and that ThreadPool
works on many different methods. Its very important to me that no pop
up's ever occur; I have a
"try/catch" block around my main but any exception that the ThreadPool
creates crash's the
application (and produces a pop up). ((For example Java has the
"unhandledException(...)" method in
the "ThreadGroup" class that you can simply override)). Does C# have
something like this?

Things I've Tried:
http://msdn.microsoft.com/library/de...l=/library/en-
us/cpref/html/frlrfsystemwindowsformsapplicationclassthreadexcep tiontopic.asp

This has almost exactly what I wanted (I thought...). I add the following
to my main (and the
class)

CustomExceptionHandler eh = new CustomExceptionHandler();
Application.ThreadException += new
ThreadExceptionEventHandler(eh.OnThreadException);

internal class CustomExceptionHandler {
public void OnThreadException(object sender, ThreadExceptionEventArgs t)
{
MessageBox.Show("IsThisWorking?");
Application.Exit();
}
}

But then I have the ThreadPool invoke a method that simply throws an
excpetion and it still crash's
my program... No MessageBox is shown either. Can someone tell me what I'm
missing?
Some more information: Basically I know I can put "try/catch" blocks
around all the methods that
the ThreadPool can invoke on but it just seems ugly and theres a lot of
methods (this is what I am
currently doing). Also I don't care if I can post any messages to the
user or anything when an
uncaught exception occures (simply having the application exit would be
great so if there's a way
for my program to just disable the "XXXX has encountered a problem and
needs to close. We are sorry
for the inconvenience." Then that would also be a great solution for me if
someone knows how I can
set my program to do that...
Best Regards,
Never Best
--
----------------------------------------------
Posted with NewsLeecher v3.0 Final
* Binary Usenet Leeching Made Easy
* http://www.newsleecher.com/?usenet
----------------------------------------------

Dec 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Hubert Hermanutz | last post: by
9 posts views Thread by Claudio Di Flumeri | last post: by
19 posts views Thread by furiousmojo | last post: by
5 posts views Thread by Simon Tamman | last post: by
1 post views Thread by paulo | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.