473,850 Members | 2,036 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Application unhandled exception event question

Bob
In Vs 2005 you have new applicationsEve nts.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(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnTest.Click

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

Dim x As Specialized.Nam eValueCollectio n

MessageBox.Show (x.Count.ToStri ng)

MessageBox.Show ("Applicatio n 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.

' UnhandledExcept ion: Raised if the application encounters an unhandled
exception.

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

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

Partial Friend Class MyApplication

Private Sub MyApplication_U nhandledExcepti on(ByVal sender As Object, ByVal e
As Microsoft.Visua lBasic.Applicat ionServices.Unh andledException EventArgs)
Handles Me.UnhandledExc eption

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

e.ExitApplicati on = 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 applicationEven ts.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 unhandledexecep tion
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
1 6324
On Mon, 12 Jun 2006 13:23:52 -0400, "Bob" <bd*****@sgiims .com> wrote:
In Vs 2005 you have new applicationsEve nts.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(B yVal sender As System.Object, ByVal e As
System.EventAr gs) Handles btnTest.Click

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

Dim x As Specialized.Nam eValueCollectio n

MessageBox.Sho w(x.Count.ToStr ing)

MessageBox.Sho w("Applicatio n 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.

' UnhandledExcept ion: Raised if the application encounters an unhandled
exception.

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

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

Partial Friend Class MyApplication

Private Sub MyApplication_U nhandledExcepti on(ByVal sender As Object, ByVal e
As Microsoft.Visua lBasic.Applicat ionServices.Unh andledException EventArgs)
Handles Me.UnhandledExc eption

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

e.ExitApplicat ion = 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 applicationEven ts.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 unhandledexecep tion
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.Thr eadException

This event allows your Windows Forms application to handle otherwise
unhandled exceptions.
Gene
Jun 12 '06 #2

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

Similar topics

12
2705
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. But, suppose I create a new thread within my app and an unhandled exception is generated in that thread, will that exception be caught here?
5
1533
by: Jason MacKenzie | last post by:
I have a production critical windows forms application. I have try catch blocks everywhere to handle every eventuality. However occasionally, every couple of months, the application crashes. Its usually a .Net Framework error message telling me there was an unhandled exception An example would be last October when the clocks rolled back. My question is: is there a way to handle an exceptions that might make it through the error...
2
4782
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 handler of my App. eg. If i throw a exception inside DragDrop, or MouseDown of an event the ThreadException does not fire !! Any ideas ???
5
6999
by: Nak | last post by:
Hi there, I have a very simple console application that I'm trying to handle the thread exception on, as I understand it there is no Application object available to a console application, so I can't use this. Instead you need to use "Thread.GetAppDomain.UnhandledException", this "works" to a certain extent but from the look if it you merely get added to a chain of event handlers, and the runtime is still above you, so I can't use this...
5
4549
by: Sam Loveridge | last post by:
Hi All. I'm hoping someone can point me in the direction of a solution to unhandled exceptions in MDI child forms causing the application to crash. I've found various articles describing a method using Application.Run(new MyMainParentForm) to place in the application's Sub Main to allow catching of unhandled exceptions in the application. The problem I'm facing is that I want to be able to trap unhandled exceptions at the MDI child...
4
2187
by: David Lozzi | last post by:
Howdy, I found a nice little book called ASP.NET 2.0 Cookbook by Michael A Kittel and Geoffrey LeBlond. Anyway, they have some instructions on how to setup application level error handling. Most of my functions have try..catch to email me about an error, then I want the application level to fire off to send the user to a custom page AND log it in the app log. When an error occurs on my page, i get a server error Server Error in...
0
863
by: Robert Dufour | last post by:
I have some things I need done in the application events unhandledexception event. I have some code in there whose execution I need to verify. In order to do that I wrote a simple button click event in my app that would fire off an unhandled exception as follows. Dim x As Specialized.NameValueCollection MessageBox.Show(x.Count.ToString) 'I should have dimmed it as new to prevent the exception
5
4543
by: Frank Rizzo | last post by:
I have a c# 2.0 winform app that runs under a user account with very limited rights. The application crashes on some actions (the Send Error to Microsoft screen) with unauthorized exception. This is despite the fact that I have try catch blocks around pretty much absolutely everything. I've tried logging to disk, but it seems to crash on a deeper level. The app works fine when run under an admin account. So how can I audit what the...
5
3286
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 it on my ftp account. I tested it out and it works perfectly , I test it by Add : "throw new Exception("Test");"
0
9895
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9744
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11011
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10725
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10352
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7900
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5931
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4547
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4142
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.