System.Runtime.InteropServices.Marshal.GetExceptionForHR Method

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

Syntax

public static Exception GetExceptionForHR (int errorCode)

Parameters

errorCode
The HRESULT to be converted.

Returns

An object that represents the converted HRESULT.

Remarks

Use the erload:System.Runtime.InteropServices.Marshal.GetExceptionForHR method to get an Exception based on an HRESULT without having to call the erload:System.Runtime.InteropServices.Marshal.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.

Requirements

Namespace: System.Runtime.InteropServices
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 2.0.0.0, 4.0.0.0
Since: .NET 2.0