I just threw an exception in MouseDown of my form and my global error
handler code caught it in the Application.ThreadException.
Here is my app.vb module if you want to compare notes: (sorry about the
mess)
HTH,
Greg
Option Strict On
Imports System.Security
Module App
'The main entry point for the application.
<STAThread()> Public Sub Main()
Try
'Demand full trust permissions
Dim fullTrust As New
PermissionSet(Permissions.PermissionState.Unrestricted)
fullTrust.Demand()
SubMain()
Catch ex As SecurityException
' Report that permissions were not full trust
MessageBox.Show("This application requires full-trust security
permissions to execute.")
Catch ex As Exception
HandleUnhandledException(ex)
End Try
End Sub
Private Sub SubMain()
' // Setup unhandled exception handlers
AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf
OnUnhandledException
'AppDomain.CurrentDomain.UnhandledException += // CLR
' new UnhandledExceptionEventHandler(OnUnhandledException);
AddHandler Application.ThreadException, AddressOf
OnGuiUnhandedException
'Application.ThreadException += // Windows Forms
' new System.Threading.ThreadExceptionEventHandler(
' OnGuiUnhandedException);
'Application.EnableVisualStyles()
Application.Run(New Main)
End Sub
'// CLR unhandled exception
Private Sub OnUnhandledException(ByVal sender As Object, ByVal e As
UnhandledExceptionEventArgs)
HandleUnhandledException(e.ExceptionObject)
End Sub
' // Windows Forms unhandled exception
Private Sub OnGuiUnhandedException(ByVal sender As Object, ByVal e As
System.Threading.ThreadExceptionEventArgs)
HandleUnhandledException(e.Exception)
End Sub
Private Sub HandleUnhandledException(ByVal o As Object)
'Dim e As Exception = CType(o, Exception)
'If Not (e Is Nothing) Then ' // Report System.Exception info
' Debug.WriteLine("Exception = " + e.GetType());
' Debug.WriteLine("Message = " + e.Message);
' Debug.WriteLine("FullText = " + e.ToString());
'Else ' // Report exception Object info
' Debug.WriteLine("Exception = " + o.GetType());
' Debug.WriteLine("FullText = " + o.ToString());
'End If
MessageBox.Show("An unhandled exception occurred and the application
is shutting down.")
Environment.Exit(1) ' // Shutting down
End Sub
End Module