Solved

Capture an unhandled exception

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Syntax Error 2 62
Not seen Link button 5 37
Where did System.Data.Objects go? 2 23
Need to learn more about SecurityProtocolType.Tls12 3 27
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

816 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

12 Experts available now in Live!

Get 1:1 Help Now