Question : Global Error Handling - winform

Hello Experts!  I'd like a global error handler for a vb.net windows forms applications.
Every example I look at either references the Main() method (which I don't have in my application)
OR
Application.ThreadException  (which I can't seem to resolve)

could someone paste working code for a global error handler for a Windows Application (forms based, not console app)

Answer : Global Error Handling - winform

That's because you're testing it in DEBUG mode.

Put this in the ApplicationEvents class:

        Private Sub MyApplication_UnhandledException(ByVal sender As Object, _
            ByVal e As Microsoft.VisualBasic.ApplicationServices.UnhandledExceptionEventArgs) _
            Handles Me.UnhandledException

            MsgBox("An error was thrown, but not handled.  The error was:  " & e.Exception.Message)

        End Sub



In the Load event of the first form that loads when your project, put:

    Private Sub Form1_Load(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles MyBase.Load

        Throw New Exception("This is an unhandled exception")

    End Sub


Change the Solution Configuration from "DEBUG" to "RELEASE", then Build your project (Build menu |
     Build Solution).  

Go to the executible (bin\Release\) and double-click it (running it outside of the VS IDE).

Random Solutions  
 
programming4us programming4us