WindowsFormsApplicationBase.UnhandledException Ereignis
Definition
Kommt vor, wenn in der Anwendung eine unbehandelte Ausnahme auftritt.Occurs when the application encounters an unhandled exception.
public:
event Microsoft::VisualBasic::ApplicationServices::UnhandledExceptionEventHandler ^ UnhandledException;
public event Microsoft.VisualBasic.ApplicationServices.UnhandledExceptionEventHandler UnhandledException;
member this.UnhandledException : Microsoft.VisualBasic.ApplicationServices.UnhandledExceptionEventHandler
Public Custom Event UnhandledException As UnhandledExceptionEventHandler
Ereignistyp
Beispiele
Dieses Beispiel verwendet das- My.Application.UnhandledException
Ereignis, um alle nicht behandelten Ausnahmen zu protokollieren.This example uses the My.Application.UnhandledException
event to log any unhandled exceptions.
Sie müssen den Code im Code-Editor-Fenster für Anwendungs Ereignisse eingeben.You must enter the code in the Code Editor window for application events. Um auf dieses Fenster zuzugreifen, befolgen Sie das in diesem Thema beschriebene Verfahren.To access this window, follow the procedure found in this topic's Remarks section. Weitere Informationen finden Sie unter Application Page, Project Designer (Visual Basic).For more information, see Application Page, Project Designer (Visual Basic).
Da das- UnhandledException
Ereignis nicht ausgelöst wird, wenn ein Debugger an die Anwendung angefügt ist, müssen Sie dieses Beispiel außerhalb der integrierten Visual Studio-Entwicklungsumgebung ausführen.Because the UnhandledException
event is not raised when a debugger is attached to the application, you have to run this example outside the Visual Studio Integrated Development Environment.
Private Sub MyApplication_UnhandledException(
sender As Object,
e As Microsoft.VisualBasic.ApplicationServices.UnhandledExceptionEventArgs
) Handles Me.UnhandledException
My.Application.Log.WriteException(e.Exception,
TraceEventType.Critical,
"Unhandled Exception.")
End Sub
Hinweise
Eine Anwendung löst das-Ereignis aus, UnhandledException
Wenn eine nicht behandelte Ausnahme auftritt.An application raises the UnhandledException
event when it encounters an unhandled exception. Dieses Ereignis ist Teil des Visual Basic Anwendungs Modells.This event is part of the Visual Basic Application model. Weitere Informationen finden Sie unter Übersicht über das Visual Basic-Anwendungsmodell.For more information, see Overview of the Visual Basic Application Model.
Sie können die- Exception Eigenschaft des- e
Parameters verwenden, um auf die nicht behandelte Ausnahme zuzugreifen, die dieses Ereignis verursacht hat.You can use the Exception property of the e
parameter to access the unhandled exception that caused this event.
Sie können die- ExitApplication Eigenschaft des- e
Parameters verwenden, um zu steuern, ob die Anwendung beendet wird.You can use the ExitApplication property of the e
parameter to control whether the application exits. Standardmäßig ExitApplication ist True
.By default, ExitApplication is True
. Daher wird die Anwendung beendet, nachdem der- UnhandledException
Ereignishandler abgeschlossen wurde.Therefore, the application exits after completing the UnhandledException
event handler. Sie können den Wert im- False
UnhandledException
Ereignishandler auf festlegen, damit die Anwendung weiterhin ausgeführt wird und Sie in den Wartezustand zurückkehrt.You can set the value to False
in the UnhandledException
event handler to keep the application running, and have it return to a waiting state.
Der Code für den UnhandledException
Ereignishandler wird in der Datei "ApplicationEvents. vb" gespeichert, die standardmäßig ausgeblendet ist.The code for the UnhandledException
event handler is stored in the ApplicationEvents.vb file, which is hidden by default.
So greifen Sie auf das Code-Editor-Fenster für Anwendungs Ereignisse zuTo access the Code Editor window for application events |
1. Wenn Sie ein Projekt in Projektmappen-Explorerausgewählt haben, klicken Sie im Menü Projekt auf Eigenschaften .1. With a project selected in Solution Explorer, click Properties on the Project menu. 2. Klicken Sie auf die Registerkarte Anwendung .2. Click the Application tab. 3. Klicken Sie auf die Schaltfläche Anwendungs Ereignisse anzeigen , um den Code-Editor zu öffnen.3. Click the View Application Events button to open the Code Editor. |
Weitere Informationen finden Sie unter Application Page, Project Designer (Visual Basic).For more information, see Application Page, Project Designer (Visual Basic).
Hinweis
Der Visual Basic-Compiler verhindert, dass Anwendungen, die für das Debuggen erstellt wurden, dieses Ereignis lösen, damit ein Debugger die nicht behandelten Ausnahmen behandeln kann.The Visual Basic compiler prevents applications that are built for debugging from raising this event, to enable a debugger to handle the unhandled exceptions. Dies bedeutet, dass der UnhandledException
Ereignishandler nicht aufgerufen wird, wenn Sie die Anwendung testen, indem Sie Sie unter dem Visual Studio-Debugger für die integrierte Entwicklungsumgebung ausführen.This means that if you are testing your application by running it under the Visual Studio Integrated Development Environment debugger, your UnhandledException
event handler will not be called. Weitere Informationen zum Entwickeln von Anwendungen für das Debuggen finden Sie unter /Debug (Visual Basic).For more information about building applications for debugging, see /debug (Visual Basic).
AufgabenTasks
In der folgenden Tabelle sind Beispiele für Aufgaben aufgeführt, die das- My.Application.UnhandledException
Ereignis betreffen.The following table lists examples of tasks that involve the My.Application.UnhandledException
event.
BeschreibungTo | SieheSee |
---|---|
Nicht behandelte Ausnahmen protokollierenLog unhandled exceptions | How to: Protokollieren von AusnahmenHow to: Log Exceptions |
Verfügbarkeit nach ProjekttypAvailability by Project Type
ProjekttypProject type | VerfügbarAvailable |
---|---|
Windows Forms-AnwendungWindows Forms Application | JaYes |
KlassenbibliothekClass Library | NeinNo |
KonsolenanwendungConsole Application | NeinNo |
Windows Forms-SteuerelementbibliothekWindows Forms Control Library | NeinNo |
WebsteuerelementbibliothekWeb Control Library | NeinNo |
Windows-DienstWindows Service | NeinNo |
WebsiteWeb Site | NeinNo |