ExceptionHandler ExceptionHandler ExceptionHandler ExceptionHandler Class

Definição

Estenda a classe ExceptionHandler para criar um manipulador de exceção para exceções sem tratamento que ocorrem dentro do tempo de execução do WCF (Windows Communication Foundation).Extend the ExceptionHandler class to create an exception handler for unhandled exceptions that occur within the Windows Communication Foundation (WCF) runtime.

public ref class ExceptionHandler abstract
public abstract class ExceptionHandler
type ExceptionHandler = class
Public MustInherit Class ExceptionHandler
Herança
ExceptionHandlerExceptionHandlerExceptionHandlerExceptionHandler

Exemplos

O exemplo de código a seguir mostra uma implementação ExceptionHandler da classe abstrata que substitui HandleException o método.The following code example shows an implementation of the ExceptionHandler abstract class that overrides the HandleException method.

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

O exemplo de código a seguir mostra como habilitar o MyExceptionHandler personalizado para exceções sem tratamento que ocorrem dentro do tempo de execução do WCF.The following code example shows how to enable the custom MyExceptionHandler for unhandled exceptions that occur within the WCF runtime.

    static void Main(string[] args)
    {
        // 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

Comentários

Estenda a ExceptionHandler classe e substitua o HandleException método para determinar se uma exceção deve encerrar o aplicativo.Extend the ExceptionHandler class and override the HandleException method to determine whether an exception should terminate the application. Em seguida, crie uma nova instância de ExceptionHandler sua classe personalizada e atribua-a AsynchronousThreadExceptionHandler à TransportExceptionHandler propriedade ou estática antes de criar clientes ou serviços WCF.Then create a new instance of your custom ExceptionHandler class and assign it to the static AsynchronousThreadExceptionHandler or TransportExceptionHandler property prior to creating WCF clients or services.

Construtores

ExceptionHandler() ExceptionHandler() ExceptionHandler() ExceptionHandler()

Inicializa uma nova instância da classe ExceptionHandler.Initializes a new instance of the ExceptionHandler class.

Propriedades

AlwaysHandle AlwaysHandle AlwaysHandle AlwaysHandle

Obtém uma instância de ExceptionHandler que trata todas as exceções.Gets an instance of ExceptionHandler that handles all exceptions.

AsynchronousThreadExceptionHandler AsynchronousThreadExceptionHandler AsynchronousThreadExceptionHandler AsynchronousThreadExceptionHandler

Obtém ou define a implementação ExceptionHandler atual para o domínio do aplicativo.Gets or sets the current ExceptionHandler implementation for the application domain.

TransportExceptionHandler TransportExceptionHandler TransportExceptionHandler TransportExceptionHandler

Obtém ou define a implementação ExceptionHandler de transporte atual para o domínio do aplicativo.Gets or sets the current transport ExceptionHandler implementation for the application domain.

Métodos

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determina se o objeto especificado é igual ao objeto atual.Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Serve como a função de hash padrão.Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

Obtém o Type da instância atual.Gets the Type of the current instance.

(Inherited from Object)
HandleException(Exception) HandleException(Exception) HandleException(Exception) HandleException(Exception)

Quando substituído em uma classe derivada, retorna true se a exceção tiver sido tratada ou false se a exceção precisar ser gerada novamente e o aplicativo encerrado.When overridden in a derived class, returns true if the exception has been handled, or false if the exception should be rethrown and the application terminated.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Cria uma cópia superficial do Object atual.Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

Retorna uma cadeia de caracteres que representa o objeto atual.Returns a string that represents the current object.

(Inherited from Object)

Aplica-se a