Marshal.GetHRForException(Exception) 方法

定义

将指定异常转换为 HRESULT。

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

参数

e
Exception

要转换为 HRESULT 的异常。

返回

Int32

映射到所提供的异常的 HRESULT。

属性

注解

GetHRForException 此外,为可通过调用 COM GetErrorInfoNEEDGUID 函数获取的异常设置 IErrorInfoInfo 接口。 可以使用此函数在应用属性的 COM 接口 PreserveSigAttribute 的托管类实现上返回 HRESULT 值。 让特性化方法捕获所有异常,并使用 GetHRForException 该方法返回相应的 HRESULT 值。 允许异常在方法外部传播会生成不正确的行为。 (事实上,公共语言运行时无法向通过 v-table.) 调用此类方法的 COM 客户端传递异常

请注意,该方法 GetHRForException 设置当前线程的 IErrorInfo 接口。 这可能会导致方法出现意外的结果,例如 ThrowExceptionForHR 默认使用当前线程的 IErrorInfo 的方法(如果已设置)。

适用于

另请参阅