Handling Unhandled Exceptions

foster

New member
Joined
Aug 2, 2005
Messages
4
Programming Experience
1-3
I'm working on a program and I'd like to have a customized error dialog box display when the program encounters an unhandled exception. I designed the form and consulted the Microsoft Help files to learn how to do this, but the sample code they provided is failing to produce the desired results. Here's what I have:

VB.NET:
Public Sub New()
    MyBase.New()
     'This call is required by the Windows Form Designer.
    InitializeComponent()

    'Add any initialization after the InitializeComponent() call

    AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf BadException

    Throw New ApplicationException("Test exception")
End Sub

Public Sub BadException(ByVal sender As Object, ByVal args As UnhandledExceptionEventArgs)
    Dim ExHandler As New Exception_Handler()
    ExHandler.ExceptionObject = CType(args.ExceptionObject, Exception)
End Sub

I've run the program both in Debug and Release configurations, and I still get the Visual Studio exception dialog, not my custom dialog. Any suggestions?
 
Last edited:
Back
Top