ExceptionHandler.HandleException(Exception) メソッド

定義

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

public:
 abstract bool HandleException(Exception ^ exception);
public abstract bool HandleException(Exception exception);
abstract member HandleException : Exception -> bool
Public MustOverride Function HandleException (exception As Exception) As Boolean

パラメーター

exception
Exception

Windows Communication Foundation (WCF) ランタイム内で発生し、アプリケーションを終了する可能性がある例外。

返品

true 例外が処理された場合。それ以外の場合は false

次のコード例は、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 を有効にする方法を示しています。

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

注釈

HandleException(Exception) メソッドは、例外が処理された場合にtrueを返します。 falseを返すか、別の例外をスローした場合、元の例外が再スローされます。

適用対象