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 介面的 Managed 類別實作上傳回 HRESULT 值。 讓屬性方法攔截所有例外狀況,並使用 GetHRForException 方法來傳回適當的 HRESULT 值。 允許例外狀況在 方法外部傳播會產生不正確的行為。 (事實上,Common Language Runtime 無法將例外狀況傳遞給透過 v-table.) 呼叫這類方法的 COM 用戶端

請注意,方法 GetHRForException 會設定目前線程的 IErrorInfo 介面。 這可能會導致非預期的結果,例如 ThrowExceptionForHR 預設使用目前線程之 IErrorInfo 的方法。

適用於

另請參閱