ExceptionHandler Klass

Definition

Utöka klassen ExceptionHandler för att skapa en undantagshanterare för ohanterade undantag som inträffar inom Windows Communication Foundation-körningen (WCF).

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

Exempel

I följande kodexempel visas en implementering av den ExceptionHandler abstrakta klass som åsidosätter HandleException metoden.

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

I följande kodexempel visas hur du aktiverar anpassad MyExceptionHandler för ohanterade undantag som inträffar inom WCF-körningen.

// 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

Kommentarer

ExceptionHandler Utöka klassen och åsidosätt HandleException metoden för att avgöra om ett undantag ska avsluta programmet. Skapa sedan en ny instans av din anpassade ExceptionHandler klass och tilldela den till den statiska AsynchronousThreadExceptionHandler egenskapen eller TransportExceptionHandler egenskapen innan du skapar WCF-klienter eller -tjänster.

Konstruktorer

Name Description
ExceptionHandler()

Initierar en ny instans av ExceptionHandler klassen.

Egenskaper

Name Description
AlwaysHandle

Hämtar en instans av ExceptionHandler som hanterar alla undantag.

AsynchronousThreadExceptionHandler

Hämtar eller anger den aktuella ExceptionHandler implementeringen för programdomänen.

TransportExceptionHandler

Hämtar eller anger den aktuella transportimplementeringen ExceptionHandler för programdomänen.

Metoder

Name Description
Equals(Object)

Avgör om det angivna objektet är lika med det aktuella objektet.

(Ärvd från Object)
GetHashCode()

Fungerar som standard-hash-funktion.

(Ärvd från Object)
GetType()

Hämtar den aktuella instansen Type .

(Ärvd från Object)
HandleException(Exception)

När det åsidosättas i en härledd klass returneras true om undantaget har hanterats, eller false om undantaget ska förnyas och programmet avslutas.

MemberwiseClone()

Skapar en ytlig kopia av den aktuella Object.

(Ärvd från Object)
ToString()

Returnerar en sträng som representerar det aktuella objektet.

(Ärvd från Object)

Gäller för