Solved

Capture an unhandled exception

Posted on 2006-07-15
3
393 Views
Last Modified: 2008-02-01
Hi,

I had posted the Q earlier:
http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/Q_21910343.html 
and got an answer that was working perfect untill I came across this:

As said earlier,  I put the event handler code in the main form's load event. In the form's load event there is another event handler that calls a sub whenever the binding manager's record changes. I am getting an error in this sub (before the form loads) and that error was unhandled,  I was expecting  the exception handler sub to take care of it. It didn't. I then tried adding a module, putting a sub main and the exception event handler code in it and calling this module at the start of the application (as suggested in the original Q).  It still ends up with the unhandled exception.

I would like to know what modification is needed there?

Thanks,
Gauri

0
Comment
Question by:p_gauri7
3 Comments
 
LVL 14

Expert Comment

by:Ramuncikas
ID: 17116972
I would simulate (if possible) conditions to get error to know what sub raises it. Then, if possible, convert sub to function and put a try...catch block into it. If error occures the function would return false otherwise true (or vice versa). Then you could put a flag depending on function's result.
0
 
LVL 3

Accepted Solution

by:
Pigtor earned 500 total points
ID: 17122320
There are two handlers that must be declared:
The ThreadException doesn't necessary terminate the thread, the UnhandledException is thrown before the application terminates.


1.  Application.ThreadException
This event enables an application to handle an exception intelligently when it receives a thread exception from a window procedure. Attach your event handlers to the ThreadException event to deal with the exception. An appropriate event handler does not terminate the thread, and allow your application to continue executing.

2.  AppDomain.UnhandledException
The UnhandledExceptionEventHandler delegate for this event provides default handling for uncaught exceptions. When this event is not handled, the system default handler reports the exception to the user and terminates the application.


--------------------------------------------------------------------------------------------------------------------------------

Public Sub New()
        MyBase.New()
        AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf UnhandledException
        AddHandler Application.ThreadException, AddressOf UnhandledException

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call
End Sub

Private Sub UnhandledException(ByVal sender As Object, ByVal args As UnhandledExceptionEventArgs)
     .....
End Sub

Private Sub UnhandledException(ByVal sender As Object, ByVal e As Threading.ThreadExceptionEventArgs)
     .....
End Sub



0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Batch file or script with password 22 69
Dot Net 4.6.1 installation fails on W2012 R2 server 14 42
parsing JSON help 1 20
IDE for Python 5 27
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question