ExceptionHandler クラス

定義

ExceptionHandler クラスを拡張し、Windows Communication Foundation (WCF) ランタイム内で発生する未処理の例外に対する例外ハンドラーを作成します。

public ref class ExceptionHandler abstract
public abstract class ExceptionHandler
type ExceptionHandler = class
Public MustInherit Class ExceptionHandler
継承
ExceptionHandler

次のコード例は、ExceptionHandler メソッドをオーバーライドする HandleException 抽象クラスを実装しています。

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

次のコード例は、WCF ランタイム内で発生する未処理の例外に対してカスタム MyExceptionHandler を有効にする方法を示しています。

    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

注釈

ExceptionHandler クラスを拡張し、HandleException メソッドをオーバーライドして、例外によりアプリケーションを修了する必要があるかどうかを判定します。 次に、カスタム ExceptionHandler クラスの新しいインスタンスを作成し、WCF クライアントまたはサービスを作成する前に静的 AsynchronousThreadExceptionHandler または TransportExceptionHandler プロパティに割り当てます。

コンストラクター

ExceptionHandler()

ExceptionHandler クラスの新しいインスタンスを初期化します。

プロパティ

AlwaysHandle

すべての例外を処理する ExceptionHandler のインスタンスを取得します。

AsynchronousThreadExceptionHandler

アプリケーション ドメインの現在の ExceptionHandler の実装を取得または設定します。

TransportExceptionHandler

アプリケーション ドメインの現在のトランスポート ExceptionHandler の実装を取得または設定します。

メソッド

Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
HandleException(Exception)

派生クラスでオーバーライドされると、例外が処理された場合は true を返し、例外を再スローしてアプリケーションを終了する必要がある場合は false を返します。

MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

適用対象