Problem with Application.ThreadException

  • Thread starter Thread starter Alex
  • Start date Start date
A

Alex

My Problem is that although i have added a handler to
Application.ThreadException and it works fine for my application exceptions,
it does not fire if an exception is generated inside an event handler of my
App.

eg. If i throw a exception inside DragDrop, or MouseDown of an event the
ThreadException does not fire !!

Any ideas ???

Thanks in advance
 
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
 
Well Greg, first of all thanks for your response.
I used your code in my app, and yes an error on mouse down really
raises the threadexception event, but when i throw an exception from
the DragDrop event of a treeview... guess what.... nothing happens !!!

What is going on here ?
 
Back
Top