Прочитај на енглеском Уреди

Делите путем


ExceptionHandler Class

Definition

Extend the ExceptionHandler class to create an exception handler for unhandled exceptions that occur within the Windows Communication Foundation (WCF) runtime.

C#
public abstract class ExceptionHandler
Inheritance
ExceptionHandler

Examples

The following code example shows an implementation of the ExceptionHandler abstract class that overrides the HandleException method.

C#
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;
            }
    }

The following code example shows how to enable the custom MyExceptionHandler for unhandled exceptions that occur within the WCF runtime.

C#
    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
    }
}

Remarks

Extend the ExceptionHandler class and override the HandleException method to determine whether an exception should terminate the application. 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.

Constructors

ExceptionHandler()

Initializes a new instance of the ExceptionHandler class.

Properties

AlwaysHandle

Gets an instance of ExceptionHandler that handles all exceptions.

AsynchronousThreadExceptionHandler

Gets or sets the current ExceptionHandler implementation for the application domain.

TransportExceptionHandler

Gets or sets the current transport ExceptionHandler implementation for the application domain.

Methods

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
HandleException(Exception)

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()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to

Производ Верзије
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1