Marshal.GetExceptionForHR Metodo

Definizione

Converte un codice errore HRESULT in un oggetto Exception corrispondente.

Overload

GetExceptionForHR(Int32)

Converte il codice errore HRESULT specificato in un oggetto Exception corrispondente.

GetExceptionForHR(Int32, IntPtr)

Converte il codice di errore HRESULT specificato in un oggetto Exception corrispondente, con ulteriori informazioni sull'errore passate in un'interfaccia IErrorInfo per l'oggetto eccezione.

GetExceptionForHR(Int32)

Source:
Marshal.cs
Source:
Marshal.cs
Source:
Marshal.cs

Converte il codice errore HRESULT specificato in un oggetto Exception corrispondente.

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

Parametri

errorCode
Int32

Codice errore HRESULT da convertire.

Restituisce

Oggetto che rappresenta il valore HRESULT convertito oppure null se il valore HRESULT non rappresenta un codice errore (ad esempio, S_OK o S_FALSE).

Attributi

Commenti

Usare il GetExceptionForHR metodo per ottenere un Exception oggetto basato su HRESULT senza dover chiamare il ThrowExceptionForHR metodo e rilevare l'eccezione.

L'interfaccia IErrorInfo corrente viene usata per costruire l'eccezione.

Per il mapping da ogni HRESULT alla classe di eccezione paragonabile in .NET Framework, vedere Procedura: Mapping di HRESULTs e Eccezioni.

Vedi anche

Si applica a

GetExceptionForHR(Int32, IntPtr)

Source:
Marshal.cs
Source:
Marshal.cs
Source:
Marshal.cs

Converte il codice di errore HRESULT specificato in un oggetto Exception corrispondente, con ulteriori informazioni sull'errore passate in un'interfaccia IErrorInfo per l'oggetto eccezione.

public:
 static Exception ^ GetExceptionForHR(int errorCode, IntPtr errorInfo);
[System.Security.SecurityCritical]
public static Exception GetExceptionForHR (int errorCode, IntPtr errorInfo);
public static Exception? GetExceptionForHR (int errorCode, IntPtr errorInfo);
public static Exception GetExceptionForHR (int errorCode, IntPtr errorInfo);
[<System.Security.SecurityCritical>]
static member GetExceptionForHR : int * nativeint -> Exception
static member GetExceptionForHR : int * nativeint -> Exception
Public Shared Function GetExceptionForHR (errorCode As Integer, errorInfo As IntPtr) As Exception

Parametri

errorCode
Int32

Codice errore HRESULT da convertire.

errorInfo
IntPtr

nativeint

Puntatore all'interfaccia IErrorInfo che fornisce informazioni aggiuntive sull'errore. È possibile specificare IntPtr(0) per usare l'interfaccia IErrorInfo corrente oppure IntPtr(-1) per ignorare l'interfaccia IErrorInfo corrente e costruire l'eccezione unicamente dal codice errore.

Restituisce

Oggetto che rappresenta il valore HRESULT convertito e le informazioni ottenute da errorInfo oppure null se un valore HRESULT non rappresenta un codice errore (ad esempio, S_OK o S_FALSE).

Attributi

Commenti

Usare il GetExceptionForHR metodo per ottenere un Exception oggetto basato su UN HRESULT senza dover chiamare il ThrowExceptionForHR metodo e rilevare l'eccezione (evitando così il sovraccarico delle prestazioni corrispondente). Il errorInfo parametro fornisce informazioni aggiuntive sull'errore, ad esempio la relativa descrizione testuale e l'identificatore univoco globale (GUID) per l'interfaccia che ha definito l'errore.

Usare questo overload di metodo se sono presenti informazioni di errore personalizzate che è necessario fornire nella conversione.

Per il mapping da ogni HRESULT alla classe di eccezione paragonabile in .NET Framework, vedere Procedura: Mapping di HRESULTs e Eccezioni.

Vedi anche

Si applica a