UnhandledException Event


UnhandledException Event

Location

My.Application.UnhandledException

Syntax

     Public Sub Me_UnhandledException(ByVal sender As Object, _        ByVal e As UnhandledExceptionEventArgs) _        Handles Me.UnhandledException     End Sub 


sender (required; Object)

The control or object that raised the event


e (required; StartupEventArgs)

An event parameter that contains information about the error or exception, using the Microsoft.VisualBasic.ApplicationServices.UnhandledExceptionEventArgs class

Description

The UnhandledException event occurs when an exception occurs in your application that is not handled by any other exception handle. Normally, when an exception occurs, it is handled by the surrounding try...Catch statement or by the On Error handler in effect for the procedure. If such handlers do not exist, the exception moves up the call stack, checking for active event handlers at each procedure in the stack. If there are no active event handlers in any of those procedures, the UnhandledException event is ultimately called.

Public Members

The e argument to this event, as an instance of the UnhandledExceptionEventArgs class, includes the following notable public members.

Member

Description

Exception

Property. A System.Exception instance that provides the details of the exception.

ExitApplication

Property. By default, this Boolean property is set to true, which causes the application to exit when the event exits. Setting this property to False keeps the application running.


Usage at a Glance

  • This event is only available in Windows Forms applications.

  • This event never fires when running an application built using the "Debug" compile target.

  • This event does not fire when running an application from within the Visual Studio IDE.

  • This event handler can be found in the ApplicationEvents.vb source code file for your project. This file is normally hidden, but it can be viewed by toggling the Show All Files button in the Solution Explorer window in Visual Studio.

Example

The UnhandledException event's code appears in the ApplicationEvents.vb file in a Windows Forms application.

     Namespace My        Class MyApplication           Private Sub MyApplication_UnhandledException( _                 ByVal sender As Object, ByVal e As _                 Microsoft.VisualBasic.ApplicationServices. _                 UnhandledExceptionEventArgs) _                 Handles Me.UnhandledException              MsgBox("I can't handle it!")              e.ExitApplication = True           End Sub        End Class     End Namespace 

Related Framework Entries

  • Microsoft.VisualBasic.ApplicationServices.UnhandledExceptionEventArgs

  • System.Exception Class

See Also

Application Object, Shutdown Event, Startup Event, StartupNextInstance Event




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net