ExceptionHandler Klas

Definitie

Breid de klasse ExceptionHandler uit om een uitzonderingshandler te maken voor niet-verwerkte uitzonderingen die optreden binnen de WCF-runtime (Windows Communication Foundation).

public ref class ExceptionHandler abstract
public abstract class ExceptionHandler
type ExceptionHandler = class
Public MustInherit Class ExceptionHandler
Overname
ExceptionHandler

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

Breid de ExceptionHandler klasse uit en overschrijf de HandleException methode om te bepalen of een uitzondering de toepassing moet beëindigen. Maak vervolgens een nieuw exemplaar van uw aangepaste ExceptionHandler klasse en wijs deze toe aan de statische AsynchronousThreadExceptionHandler of TransportExceptionHandler eigenschap voordat u WCF-clients of -services maakt.

Constructors

Name Description
ExceptionHandler()

Initialiseert een nieuw exemplaar van de ExceptionHandler klasse.

Eigenschappen

Name Description
AlwaysHandle

Hiermee haalt u een exemplaar van ExceptionHandler die alle uitzonderingen af.

AsynchronousThreadExceptionHandler

Hiermee haalt u de huidige ExceptionHandler implementatie voor het toepassingsdomein op of stelt u deze in.

TransportExceptionHandler

Hiermee haalt u de huidige transport-implementatie ExceptionHandler voor het toepassingsdomein op of stelt u deze in.

Methoden

Name Description
Equals(Object)

Bepaalt of het opgegeven object gelijk is aan het huidige object.

(Overgenomen van Object)
GetHashCode()

Fungeert als de standaardhashfunctie.

(Overgenomen van Object)
GetType()

Hiermee haalt u de Type huidige instantie op.

(Overgenomen van Object)
HandleException(Exception)

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.

MemberwiseClone()

Hiermee maakt u een ondiepe kopie van de huidige Object.

(Overgenomen van Object)
ToString()

Retourneert een tekenreeks die het huidige object vertegenwoordigt.

(Overgenomen van Object)

Van toepassing op