473,804 Members | 3,469 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Handling non-user code Exceptions

Is there any way to handle exceptions thrown by .NET classses? During
runtime and at seemingly random times, exceptions similar to the ones
shown at the base of this post are thrown. These errors turn themselves
into serious problems because they usually result in the application
having to exit, even though the user clicks 'Continue'. There doesnt
appear to be much information regarding these issues on forums - does
anyone know a way to handle these and stop the application from exiting?


************** Exception Text **************
System.NullRefe renceException: Object reference not set to an instance
of an object.
at System.Windows. Forms.WndProc.I nvoke(IntPtr hWnd, Int32 msg, IntPtr
wParam, IntPtr lParam)
at System.Windows. Forms.UnsafeNat iveMethods.Call WindowProc(IntP tr
wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows. Forms.NativeWin dow.DefWndProc( Message& m)
at System.Windows. Forms.Control.D efWndProc(Messa ge& m)
at System.Windows. Forms.Control.W mUpdateUIState( Message& m)
at System.Windows. Forms.Control.W ndProc(Message& m)
at System.Windows. Forms.Scrollabl eControl.WndPro c(Message& m)
at System.Windows. Forms.Container Control.WndProc (Message& m)
at System.Windows. Forms.ParkingWi ndow.WndProc(Me ssage& m)
at System.Windows. Forms.ControlNa tiveWindow.OnMe ssage(Message& m)
at System.Windows. Forms.ControlNa tiveWindow.WndP roc(Message& m)
at System.Windows. Forms.NativeWin dow.Callback(In tPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #1
4 2212
See MSDN docs on:

Application class, ThreadException event
AppDomain class, UnhandledExcept ion event

Also, try to figure out a pattern causing the exception to occur and add
exception handlers to the parts of code involved in the pattern.
Judging by the call stack, it looks like there's a faulty control or some
fancy P/Invoke takes place...

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

"vooose" <no****@microso ft.com> wrote in message
news:uG******** ********@tk2msf tngp13.phx.gbl. ..
Is there any way to handle exceptions thrown by .NET classses? During
runtime and at seemingly random times, exceptions similar to the ones
shown at the base of this post are thrown. These errors turn themselves
into serious problems because they usually result in the application
having to exit, even though the user clicks 'Continue'. There doesnt
appear to be much information regarding these issues on forums - does
anyone know a way to handle these and stop the application from exiting?


************** Exception Text **************
System.NullRefe renceException: Object reference not set to an instance
of an object.
at System.Windows. Forms.WndProc.I nvoke(IntPtr hWnd, Int32 msg, IntPtr
wParam, IntPtr lParam)
at System.Windows. Forms.UnsafeNat iveMethods.Call WindowProc(IntP tr
wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows. Forms.NativeWin dow.DefWndProc( Message& m)
at System.Windows. Forms.Control.D efWndProc(Messa ge& m)
at System.Windows. Forms.Control.W mUpdateUIState( Message& m)
at System.Windows. Forms.Control.W ndProc(Message& m)
at System.Windows. Forms.Scrollabl eControl.WndPro c(Message& m)
at System.Windows. Forms.Container Control.WndProc (Message& m)
at System.Windows. Forms.ParkingWi ndow.WndProc(Me ssage& m)
at System.Windows. Forms.ControlNa tiveWindow.OnMe ssage(Message& m)
at System.Windows. Forms.ControlNa tiveWindow.WndP roc(Message& m)
at System.Windows. Forms.NativeWin dow.Callback(In tPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Nov 16 '05 #2
Thank you for your reply. I am proceeding to the documentation on those
classes.

You said:
Also, try to figure out a pattern causing the exception >to occur and addexception handlers to the parts of code involved in the >pattern


Trying very hard to figure out a pattern but its doing its best to be
truly random! :D
I am using

try
{
Application.Run (mainForm);
}
catch(Exception e) { Console.Writeli ne(e.toString() ) }
and as said before, its not caught by this block. I am thinking
somewhere in the non-user code there is a try/catch that brings up the
'Continue' dialog and then promptly exits. If this is the case, then I
assume there is no way to handle this exception? (without fixing the
original problem)

Is there any extra debugging information that can be obtained. Not
having any lines from user-code really makes this tough.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3
Voose,
I am using

try
{
Application.Run (mainForm);
}
catch(Exception e) { Console.Writeli ne(e.toString() ) }
and as said before, its not caught by this block.
And that's exactly why I refer to Application.Thr eadException event (and the
AppDomain.Unhan dledException event)!
I vaguely remember there was an exception handling Application Block from
Microsoft...if I am not mistaken and one exists, you might want to check it
out as well.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

"vooose" <no****@microso ft.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. .. Thank you for your reply. I am proceeding to the documentation on those
classes.

You said:
Also, try to figure out a pattern causing the exception >to occur and

add
exception handlers to the parts of code involved in the >pattern


Trying very hard to figure out a pattern but its doing its best to be
truly random! :D
I am using

try
{
Application.Run (mainForm);
}
catch(Exception e) { Console.Writeli ne(e.toString() ) }
and as said before, its not caught by this block. I am thinking
somewhere in the non-user code there is a try/catch that brings up the
'Continue' dialog and then promptly exits. If this is the case, then I
assume there is no way to handle this exception? (without fixing the
original problem)

Is there any extra debugging information that can be obtained. Not
having any lines from user-code really makes this tough.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Nov 16 '05 #4
We had very similar problems. Our app would crash intermittently.
Attaching with Visual Studio (managed and native), I saw the same stack
traces.

Eventually, I got a trace that made sense. The error message was
something like "Cannot call Dispose when the handle is being created".
I saw there were two threads running. The UI thread was creating a
control, as shown in your stack trace. The second thread was the
garbage collector calling Dispose as part of destroying a control from
a previously opened form. This control had not been Disposed.

It seems there is a potential for a race condition inside the .NET
Framework. If you create a control without adding it to a form, it
does not automatically get Disposed. You have to Dispose of it
manually. If you don't, the garbage collector will attempt to Dispose
of the control. Doing so requires the GC thread to make changes to
global UI data being altered simultaneously on the UI thread.

One example of a control like this is a child form. Say you create the
child form in your parent form's constructor and store it in a local
variable. You must Dispose of this Form yourself. The .NET Framework
does not and cannot do it for you.

For me, disposing of the cached controls in my form's Dispose method
fixed the problem. I hope it fixes your problems, too.

Nov 16 '05 #5

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

Similar topics

12
3558
by: Xeon | last post by:
Hi, Is there anyway to set a custom error handler which is actually a method of a class? i.e. setting the method eh() of class foo as error handler in the snippet below. class foo { function eh() { do something } }
6
6400
by: nick4soup | last post by:
I have read the CGI FAQ 'How can I avoid users hitting "submit" twice' (on http://www.htmlhelp.org/faq/cgifaq.3.html#19 ) which essentially says you have to detect it at the server, using a hidden form field. That's fair enough. My server is therefore processing a response on the first request, so what kind of HTML response should I send out on the second, duplicate,
5
1735
by: John Perks and Sarah Mount | last post by:
When handling resources in Python, where the scope of the resource is known, there seem to be two schools of thought: (1) Explicit: f = open(fname) try: # ... finally: f.close()
5
1443
by: Jason MacKenzie | last post by:
I have an application running on Windows Server 2003 that was installed using an MSI package. Every once in a while (maybe once a week), I'll see, by looking at the database that the app is not reporting as it should. When I go back and look at the machine, the app is still running, but there's a dialog open telling me about enabling JIT debugging. The problem is that it doesn't really detail what the error is at all, it just tells me...
4
4611
by: BHARAT | last post by:
Hi I am a little bit new to C's advanced topics: I need help in file handling. I have Turbo C and I wrote a simple program to write data to file: #include<stdio.h> #include<dir.h> #include<conio.h> #include<stdlib.h>
132
5631
by: Zorro | last post by:
The simplicity of stack unraveling of C++ is not without defective consequences. The following article points to C++ examples showing the defects. An engineer aware of defects can avoid hard-to-find bugs. http://distributed-software.blogspot.com/2007/01/c-exception-handling-is-defective.html Regards, zorabi@ZHMicro.com http://www.zhmicro.com http://distributed-software.blogspot.com
13
431
by: Speed | last post by:
Hi, I was wondering if there is any way to catch exceptions without knowing in advance what errors may occur. What I mean to say is that is it possible to use try {} on a bunch of lines and catch ANY exception that might have occurred within those few lines without the program crashing first ? Thanks a ton,
7
1504
by: Markus Pitha | last post by:
Hello, I still have massive problems with handling with pointers when I use them through methods or much more complicated constructs. Do you have any good and helpful links which describe these issues carefully? Thanks, Markus
3
320
by: stephanearnold | last post by:
Hello, While writing an interpreter in C, I have thought of a suggestion for some new keywords that would help to reduce C application complexity: - nullable - notnullable I have a bunch of sept_get_XXX functions that return a pointer to a struct, namely sept_Type*.
9
7817
by: Josh | last post by:
I run a Joomla website and am familiar with php in some but not all aspects. Currently I am trying to find some solutions related to session handling. Am I correct in saying that "login" is kept in sessions? I can see active sessions in my mysql database, but is that the only place this information is stored? Sessions and cookies I know are related also, but how specifically (session info stored in cookies?)? Right now, when users...
0
9708
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
10589
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10340
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
10327
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
10085
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...
1
7625
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
6857
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
5663
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2999
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.