Marshal.GetExceptionForHR Method (Int32)

 

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

Namespace:   System.Runtime.InteropServices
Assembly:  mscorlib (in mscorlib.dll)

[<SecurityCriticalAttribute>]
static member GetExceptionForHR : 
        errorCode:int -> Exception

Parameters

errorCode
Type: System.Int32

The HRESULT to be converted.

Return Value

Type: System.Exception

An object that represents the converted HRESULT.

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.

SecurityCriticalAttribute

requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code.

Universal Windows Platform
Available since 8
.NET Framework
Available since 2.0
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
Show: