Partager via


ErrorHandler Class

Definition

Provides methods for dealing with common COM error codes.

public ref class ErrorHandler sealed
public ref class ErrorHandler sealed
class ErrorHandler sealed
public sealed class ErrorHandler
type ErrorHandler = class
Public NotInheritable Class ErrorHandler
Inheritance
ErrorHandler

Methods

CallWithCOMConvention(Action, Boolean)

Use CallWithCOMConvention when an interop interface might be implemented by managed code and it is expected to return HRESULT error codes but also throws exceptions. This method will catch all but critical exceptions and return the corresponding HRESULT for the caught exception.

Call as follows: hr = ErrorHandler.CallWithCOMConvention(delegate() { object.method(param); }); } or hr = ErrorHandler.CallWithCOMConvention(() => object.method(param)); }

CallWithCOMConvention(Func<Int32>, Boolean)

Use CallWithCOMConvention when an interop interface might be implimentd by managed code and it is expected to return HRESULT error codes but also throws exceptions. This method will catch all but critical exceptions and return the corresponding HRESULT for the caught exception.

Call as follows: hr = ErrorHandler.CallWithCOMConvention(delegate() { object.method(param); }); } or hr = ErrorHandler.CallWithCOMConvention(() => object.method(param)); }

ContainsCriticalException(AggregateException)
ExceptionToHResult(Exception, Boolean)

Convert the given Exception into a COM HRESULT return code and set the COM error info on the calling thread. Optionally, report that error to the user.

Failed(Int32)

Checks if a HRESULT is an error return code.

IsCriticalException(Exception)

Returns true if the Exception is one of:

These exceptions should be re-thrown even the exception would cross a COM boundary. Such exceptions are considered critical and should immediately terminate the application.
IsRejectedRpcCall(Int32)

Checks if the parameter is a failure HRESULT indicating a failed RPC call that may succeed if retried at a later time.

Succeeded(Int32)

Checks if a HRESULT is a success return code.

ThrowOnFailure(Int32, Int32[])

Checks if the parameter is a success or failure HRESULT and throws an exception if it is a failure that is not included in the array of well-known failures.

ThrowOnFailure(Int32)

Checks if the parameter is a success or failure HRESULT and throws an exception in case of failure.

Applies to