473,614 Members | 2,508 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Catching every unhandled exception?

Elp
Hi,

I've developped a Window Form C# application which main form contains
several activex controls. No problems most of the time but on some machine,
the application crashes when the main form is closed with a
NullReferenceEx ception caused by the DisposeAxContro l which, i guess, is
supposed to dispose one of my ActiveX.

This is not a big problem as the application is closing anyway but i'd like
to suppress this crash message. However, i can't find a way to catch this
exception in my application. Even when putting the whole main method in a
try catch block, this exception is not catched! How can i catch all
unhandeled exceptions in an application?
Nov 16 '05 #1
3 17206
Hi Elp,
To catch Windows Form's unhandled exception hook-up
AppDomain.Unhan dledException and Application.Thr eadException events

--
HTH
Stoitcho Goutsev (100) [C# MVP]
"Elp" <ro********@REM OVEME.hotmail.c om> wrote in message
news:O8******** ******@TK2MSFTN GP09.phx.gbl...
Hi,

I've developped a Window Form C# application which main form contains
several activex controls. No problems most of the time but on some machine, the application crashes when the main form is closed with a
NullReferenceEx ception caused by the DisposeAxContro l which, i guess, is
supposed to dispose one of my ActiveX.

This is not a big problem as the application is closing anyway but i'd like to suppress this crash message. However, i can't find a way to catch this
exception in my application. Even when putting the whole main method in a
try catch block, this exception is not catched! How can i catch all
unhandeled exceptions in an application?

Nov 16 '05 #2
Elp,
In addition to the other comments.

Depending on the type of application you are creating, .NET has three
different global exception handlers.

For ASP.NET look at:
System.Web.Http Application.Err or event
Normally placed in your Global.asax file.

For console applications look at:
System.AppDomai n.UnhandledExce ption event
Use AddHandler in your Sub Main.

For Windows Forms look at:
System.Windows. Forms.Applicati on.ThreadExcept ion event
Use AddHandler in your Sub Main.

It can be beneficial to combine the above global handlers in your app, as
well as wrap your Sub Main in a try catch itself.

There is an article in the June 2004 MSDN Magazine that shows how to
implement the global exception handling in .NET that explains why & when you
use multiple of the above handlers...

http://msdn.microsoft.com/msdnmag/is...T/default.aspx

For example: In my Windows Forms apps I would have a handler attached to the
Application.Thr eadException event, plus a Try/Catch in my Main. The
Try/Catch in Main only catches exceptions if the constructor of the MainForm
raises an exception, the Application.Thr eadException handler will catch all
uncaught exceptions from any form/control event handlers.

Hope this helps
Jay
"Elp" <ro********@REM OVEME.hotmail.c om> wrote in message
news:O8******** ******@TK2MSFTN GP09.phx.gbl...
Hi,

I've developped a Window Form C# application which main form contains
several activex controls. No problems most of the time but on some machine, the application crashes when the main form is closed with a
NullReferenceEx ception caused by the DisposeAxContro l which, i guess, is
supposed to dispose one of my ActiveX.

This is not a big problem as the application is closing anyway but i'd like to suppress this crash message. However, i can't find a way to catch this
exception in my application. Even when putting the whole main method in a
try catch block, this exception is not catched! How can i catch all
unhandeled exceptions in an application?

Nov 16 '05 #3
Elp

"Stoitcho Goutsev (100) [C# MVP]" <10*@100.com> wrote in message
news:u7******** ******@TK2MSFTN GP12.phx.gbl...
Hi Elp,
To catch Windows Form's unhandled exception hook-up
AppDomain.Unhan dledException and Application.Thr eadException events


Thanks to both of you. I think that it is what i was looking for. I'll give
it a try.
Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2948
by: Professor Frink | last post by:
First off, I apologize if this gets long. I'm simply trying to give you all enough information to help me out. I'm writing (almost finished, actually), my first VB.Net application. It's a forms application that is going to be used to extract data from a legacy system (VSAM based mainframe file structure), and output data in pipe-delimited record layouts, multiple record types per file, one file per chosen client. I have been working on...
4
2245
by: Craig831 | last post by:
First off, I apologize if this gets long. I'm simply trying to give you all enough information to help me out. I'm writing (almost finished, actually), my first VB.Net application. It's a forms application that is going to be used to extract data from a legacy system (VSAM based mainframe file structure), and output data in pipe-delimited record layouts, multiple record types per file, one file per chosen client. I have been working on...
5
5734
by: Lucvdv | last post by:
Can someone explain why this code pops up a messagebox saying the ThreadAbortException wasn't handled? The first exception is reported only in the debug pane, as expected. The second (caused by thread.Abort()) is reported twice: once in the debug window, and once through the message box. Is it because the thread was sleeping when the exception occurred?
0
893
by: Gene Hubert | last post by:
I occasionally get the "Unhandled Exception" window popping up when I'm running with Debug on. I can't tell why I get the "Unhandled Exception" window instead of it catching the error and giving me a chance to break and look at the code where the error occured. Can anyone shed some light on this? Thanks, Gene H.
5
3296
by: Samuel R. Neff | last post by:
When you have an unhandled exception in vb.net how do you view the exception information in the debugger? In C# the debugger creates a local variable that points to the exception and you can view it in one of the windows (autos or locals, don't remember which). That doesn't appear to be the case with vb.net. I also tried using the command window to inspect "Err" but that gave nothing useful (always empty).
1
3320
by: Parag Mahajan | last post by:
Hello, I am using VS.Net 2003 1.1 framework. I have a VB.Net client project consuming Axis 1.1 web service. Whenever I try to create an instance of the WebService, I get the following unhandled exception. Unhandled Exception: System.IO.FileNotFoundException: File or assembly name dyz_s_41.dll, or one of its dependencies, was not found. File name: "dyz_s_41.dll"
3
2156
by: Emily | last post by:
Hi, I have the following code and an unhandled exception. Code: UnitInventory inventory; foreach (object obj in list) //debugger points to list where exception occurs {
0
1453
by: Mike S | last post by:
I'm still looking into this problem, but to summarize: I wrote a very simple Windows Service in VB.NET, as part of a larger application. I created a deployment project for the application the resulting MSI explicitly installs the service. I've ran the installer on 4 machines at our office (2 are running Windows 2000 Pro, 1 is running XP Pro, and the other is running Windows 98). On each of these machines, the installation goes without a...
1
1844
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
8198
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...
1
8294
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8444
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7115
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6093
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
5549
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
4058
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
4138
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1758
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.