ExceptionHandler.HandleException(Exception) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
파생 클래스에서 재정의된 경우 예외가 처리되었는지 또는 true 예외를 다시 throw하고 애플리케이션을 종료해야 하는지를 반환 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
WCF(Windows Communication Foundation) 런타임 내에서 발생했으며 애플리케이션을 종료할 수 있는 예외입니다.
반품
예제
다음 코드 예제에서는 메서드를 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 하거나 throw하면 원래 예외가 다시 throw됩니다.