Editare

Partajați prin


Marshal.GetExceptionForHR Method

Definition

Converts an HRESULT error code to a corresponding Exception object.

Overloads

GetExceptionForHR(Int32)

Converts the specified HRESULT error code to a corresponding Exception object.

GetExceptionForHR(Int32, IntPtr)

Converts the specified HRESULT error code to a corresponding Exception object, with additional error information passed in an IErrorInfo interface for the exception object.

GetExceptionForHR(Int32)

Source:
Marshal.cs
Source:
Marshal.cs
Source:
Marshal.cs

Converts the specified HRESULT error code to a corresponding Exception object.

public:
 static Exception ^ GetExceptionForHR(int errorCode);
[System.Security.SecurityCritical]
public static Exception GetExceptionForHR (int errorCode);
public static Exception? GetExceptionForHR (int errorCode);
public static Exception GetExceptionForHR (int errorCode);
[<System.Security.SecurityCritical>]
static member GetExceptionForHR : int -> Exception
static member GetExceptionForHR : int -> Exception
Public Shared Function GetExceptionForHR (errorCode As Integer) As Exception

Parameters

errorCode
Int32

The HRESULT to be converted.

Returns

An object that represents the converted HRESULT, or null if the HRESULT value doesn't represent an error code (for example, S_OK or S_FALSE).

Attributes

Remarks

Use the GetExceptionForHR method to get an Exception based on an HRESULT without having to call the ThrowExceptionForHR method and catch the exception.

The current IErrorInfo interface is used to construct the exception.

For the mapping from each HRESULT to its comparable exception class in the .NET Framework, see How to: Map HRESULTs and Exceptions.

See also

Applies to

GetExceptionForHR(Int32, IntPtr)

Source:
Marshal.cs
Source:
Marshal.cs
Source:
Marshal.cs

Converts the specified HRESULT error code to a corresponding Exception object, with additional error information passed in an IErrorInfo interface for the exception object.

public:
 static Exception ^ GetExceptionForHR(int errorCode, IntPtr errorInfo);
[System.Security.SecurityCritical]
public static Exception GetExceptionForHR (int errorCode, IntPtr errorInfo);
public static Exception? GetExceptionForHR (int errorCode, IntPtr errorInfo);
public static Exception GetExceptionForHR (int errorCode, IntPtr errorInfo);
[<System.Security.SecurityCritical>]
static member GetExceptionForHR : int * nativeint -> Exception
static member GetExceptionForHR : int * nativeint -> Exception
Public Shared Function GetExceptionForHR (errorCode As Integer, errorInfo As IntPtr) As Exception

Parameters

errorCode
Int32

The HRESULT to be converted.

errorInfo
IntPtr

nativeint

A pointer to the IErrorInfo interface that provides more information about the error. You can specify IntPtr(0) to use the current IErrorInfo interface, or IntPtr(-1) to ignore the current IErrorInfo interface and construct the exception just from the error code.

Returns

An object that represents the converted HRESULT and information obtained from errorInfo, or null if an HRESULT value doesn't represent an error code (for example, S_OK or S_FALSE).

Attributes

Remarks

Use the GetExceptionForHR method to get an Exception based on an HRESULT without having to call the ThrowExceptionForHR method and catch the exception (thus avoiding the corresponding performance overhead). The errorInfo parameter supplies additional information about the error, such as its textual description and the globally unique identifier (GUID) for the interface that defined the error.

Use this method overload if you have custom error information that you have to supply in the conversion.

For the mapping from each HRESULT to its comparable exception class in the .NET Framework, see How to: Map HRESULTs and Exceptions.

See also

Applies to