Home All Groups Group Topic Archive Search About

Application unhandled exception event question

Author
12 Jun 2006 5:23 PM
Bob
In Vs 2005 you have new applicationsEvents.vb I was testing it in a simple
app and found that it was easier to implement unhandled exception management
tah it was in Vs2003 (vb.net) You can, if you want to, prevent your app from
terminating on an unhandled exception, and for me this is important. In an
Ivr app it will let me hang up the phone only on the line that triggered the
unhandled exception, leaving other callers to complete their calls.
This is the sample app code

In form1

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnTest.Click

'-- just a simple "object not initialized" exception (should read "as new")

Dim x As Specialized.NameValueCollection

MessageBox.Show(x.Count.ToString)

MessageBox.Show("Application is continuing")

End Sub

End Class



In application Events.vb

Namespace My

' The following events are availble for MyApplication:

'

' Startup: Raised when the application starts, before the startup form is
created.

' Shutdown: Raised after all application forms are closed. This event is not
raised if the application terminates abnormally.

' UnhandledException: Raised if the application encounters an unhandled
exception.

' StartupNextInstance: Raised when launching a single-instance application
and the application is already active.

' NetworkAvailabilityChanged: Raised when the network connection is
connected or disconnected.

Partial Friend Class MyApplication

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

MsgBox("Sender: " & sender.ToString & " Exception:" & e.Exception.Message)

e.ExitApplication = False

End Sub

End Class

End Namespace



Quite simple really and it seems to work OK. I have one problem, I would
like to be able to single step through the applicationEvents.vb code when it
is triggered in my IDE, like when I click the button in form1 while in the
IDE but I always get The exception dialog window that gives me info about
the unhandled application and I can only test if it works by running the
compiled exe, Only then do I see the message box un the unhandledexeception
event handler.

Is there any way that I could get to that code while in debug mode?

Thanks for any help

Bob

Author
12 Jun 2006 7:53 PM
gene kelley
Show quote Hide quote
On Mon, 12 Jun 2006 13:23:52 -0400, "Bob" <bduf***@sgiims.com> wrote:

>In Vs 2005 you have new applicationsEvents.vb I was testing it in a simple
>app and found that it was easier to implement unhandled exception management
>tah it was in Vs2003 (vb.net) You can, if you want to, prevent your app from
>terminating on an unhandled exception, and for me this is important. In an
>Ivr app it will let me hang up the phone only on the line that triggered the
>unhandled exception, leaving other callers to complete their calls.
>This is the sample app code
>
>In form1
>
>Public Class Form1
>
>Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
>System.EventArgs) Handles btnTest.Click
>
>'-- just a simple "object not initialized" exception (should read "as new")
>
>Dim x As Specialized.NameValueCollection
>
>MessageBox.Show(x.Count.ToString)
>
>MessageBox.Show("Application is continuing")
>
>End Sub
>
>End Class
>
>
>
>In application Events.vb
>
>Namespace My
>
>' The following events are availble for MyApplication:
>
>'
>
>' Startup: Raised when the application starts, before the startup form is
>created.
>
>' Shutdown: Raised after all application forms are closed. This event is not
>raised if the application terminates abnormally.
>
>' UnhandledException: Raised if the application encounters an unhandled
>exception.
>
>' StartupNextInstance: Raised when launching a single-instance application
>and the application is already active.
>
>' NetworkAvailabilityChanged: Raised when the network connection is
>connected or disconnected.
>
>Partial Friend Class MyApplication
>
>Private Sub MyApplication_UnhandledException(ByVal sender As Object, ByVal e
>As Microsoft.VisualBasic.ApplicationServices.UnhandledExceptionEventArgs)
>Handles Me.UnhandledException
>
>MsgBox("Sender: " & sender.ToString & " Exception:" & e.Exception.Message)
>
>e.ExitApplication = False
>
>End Sub
>
>End Class
>
>End Namespace
>
>
>
>Quite simple really and it seems to work OK. I have one problem, I would
>like to be able to single step through the applicationEvents.vb code when it
>is triggered in my IDE, like when I click the button in form1 while in the
>IDE but I always get The exception dialog window that gives me info about
>the unhandled application and I can only test if it works by running the
>compiled exe, Only then do I see the message box un the unhandledexeception
>event handler.
>
>Is there any way that I could get to that code while in debug mode?
>
>Thanks for any help
>
>Bob
>
>
>

Have a look at:
Application.ThreadException

This event allows your Windows Forms application to handle otherwise
unhandled exceptions.


Gene