ExceptionHandler.HandleException(Exception) Methode
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Wanneer de uitzondering wordt overschreven in een afgeleide klasse, wordt geretourneerd true als de uitzondering is verwerkt of false als de uitzondering opnieuw moet worden uitgevoerd en de toepassing is beëindigd.
public:
abstract bool HandleException(Exception ^ exception);
public abstract bool HandleException(Exception exception);
abstract member HandleException : Exception -> bool
Public MustOverride Function HandleException (exception As Exception) As Boolean
Parameters
- exception
- Exception
De uitzondering die is opgetreden in de WCF-runtime (Windows Communication Foundation) en die de toepassing kan beëindigen.
Retouren
true indien de uitzondering is verwerkt; anders, false.
Voorbeelden
In het volgende codevoorbeeld ziet u een implementatie van de ExceptionHandler abstracte klasse die de HandleException methode overschrijft.
using System;
using System.ServiceModel.Dispatcher;
namespace CS
{
public class MyExceptionHandler : ExceptionHandler
{
// HandleException method override gives control to
// your code.
public override bool HandleException(Exception ex)
{
// This method contains logic to decide whether
// the exception is serious enough
// to terminate the process.
return ShouldTerminateProcess(ex);
}
public bool ShouldTerminateProcess(Exception ex)
{
// Write your logic here.
return true;
}
}
Imports System.ServiceModel.Dispatcher
Namespace CS
Public Class MyExceptionHandler
Inherits ExceptionHandler
' HandleException method override gives control to
' your code.
Public Overrides Function HandleException(ByVal ex As Exception) As Boolean
' This method contains logic to decide whether
' the exception is serious enough
' to terminate the process.
Return ShouldTerminateProcess (ex)
End Function
Public Function ShouldTerminateProcess(ByVal ex As Exception) As Boolean
' Write your logic here.
Return True
End Function
End Class
In het volgende codevoorbeeld ziet u hoe u de aangepaste MyExceptionHandler optie inschakelt voor niet-verwerkte uitzonderingen die optreden in de WCF-runtime.
// Create an instance of the MyExceptionHandler class.
MyExceptionHandler thisExceptionHandler =
new MyExceptionHandler();
// Enable the custom handler by setting
// AsynchronousThreadExceptionHandler property
// to this object.
ExceptionHandler.AsynchronousThreadExceptionHandler =
thisExceptionHandler;
// After the handler is set, write your call to
// System.ServiceModel.ICommunication.Open here.
Sub Main(ByVal args() As String)
' Create an instance of the MyExceptionHandler class.
Dim thisExceptionHandler As New MyExceptionHandler()
' Enable the custom handler by setting
' AsynchronousThreadExceptionHandler property
' to this object.
ExceptionHandler.AsynchronousThreadExceptionHandler = thisExceptionHandler
' After the handler is set, write your call to
' System.ServiceModel.ICommunication.Open here
End Sub
End Module
Opmerkingen
De HandleException(Exception) methode retourneert true als de uitzondering is verwerkt. Als deze een andere uitzondering retourneert false of genereert, wordt de oorspronkelijke uitzondering opnieuw gegooid.