473,326 Members | 2,104 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Problem with Application.ThreadException

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
Nov 20 '05 #1
2 4737
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.Unrestri cted)
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(OnUnhandledExceptio n);

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

"Alex" <al********@yahoo.gr> wrote in message
news:32**************************@posting.google.c om...
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

Nov 20 '05 #2
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 ?


"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message news:<#T**************@tk2msftngp13.phx.gbl>...
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.Unrestri cted)
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(OnUnhandledExceptio n);

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

"Alex" <al********@yahoo.gr> wrote in message
news:32**************************@posting.google.c om...
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

Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Giovanni pepe | last post by:
Hello, in a VB.NET Application I had a problem after a Drag&Drop operation from Windows Desktop (Dataformats.filedrop) to listview.... In debug there are no errors so I've decided to implement the...
12
by: Rakesh | last post by:
Hi, I am catching unhandled exception by attached an event handler on the Application.ThreadException event. This will ensure that I could handle all uncaught exceptions on the main thread. ...
2
by: Robert Scheer | last post by:
Hi. I am using Application.ThreadException together with a sub to catch unhandled exceptions on one form. My application has 4 forms. Do I need to add an event handler for the...
0
by: Alex | last post by:
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...
5
by: Matthew Hood | last post by:
I have a DLL I created to handle all unknown errors using the Application.ThreadException event. I'm asking the user if they want to terminate the program or continue. This is working like I...
2
by: paul.mason | last post by:
I was wondering if anyone else had come across this "feature" of .NET and if they had any idea what might be causing it. I've been writing my first C# Windows application (so if there's anything...
5
by: giddy | last post by:
hi, I made this little crash reporter system for my project. It works by getting hooked up to the Application.ThreadException event. If an unhandled exception occurs , it logs it and then puts...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.