By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,570 Members | 970 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,570 IT Pros & Developers. It's quick & easy.

Application unhandled exception event question

P: n/a
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.Unhandle dExceptionEventArgs)
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


Jun 12 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Mon, 12 Jun 2006 13:23:52 -0400, "Bob" <bd*****@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.Unhandle dExceptionEventArgs)
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
Jun 12 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.