共用方式為


ErrorHandler.CallWithCOMConvention Method

Definition

Overloads

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)); }

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)); }

public static int CallWithCOMConvention (Action method, bool reportError = false);
static member CallWithCOMConvention : Action * bool -> int
Public Shared Function CallWithCOMConvention (method As Action, Optional reportError As Boolean = false) As Integer

Parameters

method
Action

The action to invoke.

reportError
Boolean

True to report the error

Returns

Zero (S_OK) on success. Otherwise an HRESULT representing the exception thrown by invoking method.

Examples

hr = ErrorHandler.CallWithCOMConvention(delegate() { object.method(param); }); }  

or  

hr = ErrorHandler.CallWithCOMConvention(() => object.method(param)); }  

Applies to

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)); }

public static int CallWithCOMConvention (Func<int> method, bool reportError = false);
static member CallWithCOMConvention : Func<int> * bool -> int
Public Shared Function CallWithCOMConvention (method As Func(Of Integer), Optional reportError As Boolean = false) As Integer

Parameters

method
Func<Int32>
reportError
Boolean

Returns

Applies to