473,756 Members | 1,818 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 "unhandledExcep tion(...)" method in
the "ThreadGrou p" 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/frlrfsystemwind owsformsapplica tionclassthread exceptiontopic. asp

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

CustomException Handler eh = new CustomException Handler();
Application.Thr eadException += new ThreadException EventHandler(eh .OnThreadExcept ion);

internal class CustomException Handler {
public void OnThreadExcepti on(object sender, ThreadException EventArgs t) {
MessageBox.Show ("IsThisWorking ?");
Application.Exi t();
}
}

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 2006
Hi,

Sure do, you can use Application.Thr eadException or
AppDomain.UnHan dledExeption
Cheers,

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

"NvrBst" <Nv****@hotmail .com> wrote in message
news:11******** *************** *************** ***@roc.usenete xchange.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
"unhandledExcep tion(...)" method in
the "ThreadGrou p" 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/frlrfsystemwind owsformsapplica tionclassthread exceptiontopic. asp

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

CustomException Handler eh = new CustomException Handler();
Application.Thr eadException += new
ThreadException EventHandler(eh .OnThreadExcept ion);

internal class CustomException Handler {
public void OnThreadExcepti on(object sender, ThreadException EventArgs t)
{
MessageBox.Show ("IsThisWorking ?");
Application.Exi t();
}
}

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1848
by: Shravan | last post by:
Hi, Does anybody know how to catch unhandled exceptions in an application. I have tried using AppDomain.UnhandledException Event Application.ThreadException Event but they were not catching unhandled exceptions always. There are not working in some cases.
5
2077
by: Hubert Hermanutz | last post by:
Hi, as yet i have readed in the MSDN about exception handling. The only references that i was founded, described try, catch, finally and throw objects. But I am searching about an occation to catch exceptions central, maybe, the framework call a central function of each class, when there is throw a exception. The reason is, that i do not need try, catch... blocks and therefore the sourcecode will be going to unreadable.
12
6113
by: Vasco Lohrenscheit | last post by:
Hi, I have a Problem with unmanaged exception. In the debug build it works fine to catch unmanaged c++ exceptions from other dlls with //managed code: try { //the form loads unmanaged dlls out of which unmanaged exception //get thrown
0
975
by: Chris Joslyn | last post by:
I am integrating some legacy VC++ 6.0 classes into a managed C++.NET Windows service. After I had the basic framework in place and running, I added in the source files I needed and tried to run the service. Unfortunately, now when I run the service, I get a System.ExecutionEngineException unhandled exception. I suspect that one of the global variables/objects is causing the problem. I've been unable to find a way to trap the unhandled...
9
2210
by: Claudio Di Flumeri | last post by:
Hello all, I've added a global exception handler to my application in this way: Sub Main() AddHandler Application.ThreadException, AddressOf ThreadException AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf UnhandledException Application.Run(Main)
3
7308
by: Mike Binks | last post by:
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();
19
10212
by: furiousmojo | last post by:
This is a strange problem. I have a project where the contents of global.asax application_error are not firing. It is an asp.net 2.0 application using web application projects. I have another app using web application projects and it's firing fine but it was upgraded from the 1.1 framework. Why doesn't my global.asax application_error routine fire?
5
2230
by: Simon Tamman | last post by:
I have an object named DisasterRecovery. The Ctor of this object is this: private DisasterRecovery() { Application.ThreadException+= new System.Threading.ThreadExceptionEventHandler(Application_ThreadException); AppDomain.CurrentDomain.UnhandledException +=new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); }
1
1734
by: paulo | last post by:
Hello, I have a DLL library containing some web services which are declared in each .asmx file in the following way: <%@ WebService Language="C#" Class="LibraryName.WebService" %> I would like to log every unhandled exception that occurs on any web service declared in the library to a file. I noticed the global class, usually inside global.asax has the Application_Error event that can be
1
1852
by: aine_canby | last post by:
Hi, This is my Program class in my Application - static class Program { /// <summary> /// The main entry point for the application. /// </summary>
0
9456
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9872
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7248
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6534
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5142
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3358
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2666
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.