Solved

Capture an unhandled exception

Posted on 2006-07-15
3
391 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

920 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now