Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Capture an unhandled exception

Posted on 2006-07-15
3
Medium Priority
?
397 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 1500 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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

971 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