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 的异常。

返回

映射到提供的异常的 HRESULT。

属性

注解

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

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

适用于

另请参阅