Share via


Marshal.GetHRForException(Exception) Méthode

Définition

Convertit l'exception spécifiée en 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

Paramètres

e
Exception

Exception à convertir en HRESULT.

Retours

HRESULT mappé en l'exception fournie.

Attributs

Remarques

GetHRForException configure également une interface IErrorInfo pour l’exception qui peut être obtenue en appelant la fonction COM GetErrorInfoNEEDGUID. Vous pouvez utiliser cette fonction pour renvoyer une valeur HRESULT sur une implémentation de classe managée d’une interface COM où vous appliquez l’attribut PreserveSigAttribute . La méthode attributée intercepte toutes les exceptions et utilisez la GetHRForException méthode pour renvoyer la valeur HRESULT appropriée. Le fait d’autoriser une exception à se propager en dehors de la méthode produit un comportement incorrect. (En fait, le Common Language Runtime ne parvient pas à transmettre une exception à un client COM qui appelle une telle méthode via une table v.)

Notez que la GetHRForException méthode définit l’interface IErrorInfo du thread actif. Cela peut entraîner des résultats inattendus pour des méthodes telles que les ThrowExceptionForHR méthodes qui utilisent par défaut l’IErrorInfo du thread actuel s’il est défini.

S’applique à

Voir aussi