Sugerir traducción
 
Otros han sugerido:

progress indicator
No hay más sugerencias.
Evaluar y enviar comentarios
Contraer todo/Expandir todo Contraer todo
Ver contenido:  en paraleloVer contenido: en paralelo
.NET Framework Class Library
COMException Class

The exception that is thrown when an unrecognized HRESULT is returned from a COM method call.

Namespace:  System.Runtime.InteropServices
Assembly:  mscorlib (in mscorlib.dll)
Visual Basic
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public Class COMException _
    Inherits ExternalException
C#
[SerializableAttribute]
[ComVisibleAttribute(true)]
public class COMException : ExternalException
Visual C++
[SerializableAttribute]
[ComVisibleAttribute(true)]
public ref class COMException : public ExternalException
F#
[<SerializableAttribute>]
[<ComVisibleAttribute(true)>]
type COMException =  
    class
        inherit ExternalException
    end

The COMException type exposes the following members.

  NameDescription
Public methodCOMException()()()Initializes a new instance of the COMException class with default values.
Public methodCOMException(String)Initializes a new instance of the COMException class with a specified message.
Protected methodCOMException(SerializationInfo, StreamingContext)Initializes a new instance of the COMException class from serialization data.
Public methodCOMException(String, Exception)Initializes a new instance of the COMException class with a specified error message and a reference to the inner exception that is the cause of this exception.
Public methodCOMException(String, Int32)Initializes a new instance of the COMException class with a specified message and error code.
Top
  NameDescription
Public propertyDataGets a collection of key/value pairs that provide additional user-defined information about the exception. (Inherited from Exception.)
Public propertyErrorCodeGets the HRESULT of the error. (Inherited from ExternalException.)
Public propertyHelpLinkGets or sets a link to the help file associated with this exception. (Inherited from Exception.)
Protected propertyHResultGets or sets HRESULT, a coded numerical value that is assigned to a specific exception. (Inherited from Exception.)
Public propertyInnerExceptionGets the Exception instance that caused the current exception. (Inherited from Exception.)
Public propertyMessageGets a message that describes the current exception. (Inherited from Exception.)
Public propertySourceGets or sets the name of the application or the object that causes the error. (Inherited from Exception.)
Public propertyStackTraceGets a string representation of the immediate frames on the call stack. (Inherited from Exception.)
Public propertyTargetSiteGets the method that throws the current exception. (Inherited from Exception.)
Top
  NameDescription
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetBaseExceptionWhen overridden in a derived class, returns the Exception that is the root cause of one or more subsequent exceptions. (Inherited from Exception.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetObjectDataWhen overridden in a derived class, sets the SerializationInfo with information about the exception. (Inherited from Exception.)
Public methodGetTypeGets the runtime type of the current instance. (Inherited from Exception.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringConverts the contents of the exception to a string. (Overrides ExternalException..::.ToString()()().)
Top
  NameDescription
Protected eventSerializeObjectStateOccurs when an exception is serialized to create an exception state object that contains serialized data about the exception. (Inherited from Exception.)
Top

The common language runtime transforms well-known HRESULTs to.NET exceptions, enabling COM objects to return meaningful error information to managed clients. The HRESULT to exception mapping also works in the other direction by returning specific HRESULTs to unmanaged clients. For mapping details, see How to: Map HRESULTs and Exceptions.

When the runtime encounters an unfamiliar HRESULT (an HRESULT that lacks a specific, corresponding exception), it throws an instance of the COMException class. This all-purpose exception exposes the same members as any exception, and includes a public ErrorCode property that contains the HRESULT returned by the callee. If an error message is available to the runtime (obtained from the IErrorInfo interface or the Err object in Visual Basic, or in some cases from the operating system), the message is returned to the caller. However, if the COM component developer fails to include an error message, the runtime returns the eight-digit HRESULT in place of a message string. Having an HRESULT allows the caller to determine the cause of the generic exception.

Although you can use the COMException class to return specific HRESULTs to unmanaged clients, throwing a specific.NET exception is better than using a generic exception. Consider that managed clients as well as unmanaged clients can use your.NET object, and throwing an HRESULT to a managed caller is less comprehendible than throwing an exception.

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role not supported), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Biblioteca de clases de .NET Framework
COMException (Clase)

Excepción que se produce cuando se devuelve un valor HRESULT no reconocido desde una llamada de método COM.

Espacio de nombres:  System.Runtime.InteropServices
Ensamblado:  mscorlib (en mscorlib.dll)
Visual Basic
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public Class COMException _
    Inherits ExternalException
C#
[SerializableAttribute]
[ComVisibleAttribute(true)]
public class COMException : ExternalException
Visual C++
[SerializableAttribute]
[ComVisibleAttribute(true)]
public ref class COMException : public ExternalException
F#
[<SerializableAttribute>]
[<ComVisibleAttribute(true)>]
type COMException =  
    class
        inherit ExternalException
    end

El tipo COMException expone los siguientes miembros.

  NombreDescripción
Método públicoCOMException()()()Inicializa una nueva instancia de la clase COMException con valores predeterminados.
Método públicoCOMException(String)Inicializa una nueva instancia de la clase COMException con un mensaje especificado.
Método protegidoCOMException(SerializationInfo, StreamingContext)Inicializa una nueva instancia de la clase COMException a partir de los datos de serialización.
Método públicoCOMException(String, Exception)Inicializa una nueva instancia de la clase COMException con un mensaje de error especificado y una referencia a la excepción interna que representa la causa de esta excepción.
Método públicoCOMException(String, Int32)Inicializa una nueva instancia de la clase COMException con un mensaje y un código de error especificados.
Arriba
  NombreDescripción
Propiedad públicaDataObtiene una colección de pares de clave y valor que proporcionan información adicional definida por el usuario acerca de la excepción. (Se hereda de Exception).
Propiedad públicaErrorCodeObtiene el HRESULT del error. (Se hereda de ExternalException).
Propiedad públicaHelpLinkObtiene o establece un vínculo al archivo de ayuda asociado a esta excepción. (Se hereda de Exception).
Propiedad protegidaHResultObtiene o establece HRESULT, un valor numérico codificado que se asigna a una excepción específica. (Se hereda de Exception).
Propiedad públicaInnerExceptionObtiene la instancia Exception que produjo la excepción actual. (Se hereda de Exception).
Propiedad públicaMessageObtiene un mensaje que describe la excepción actual. (Se hereda de Exception).
Propiedad públicaSourceDevuelve o establece el nombre de la aplicación o del objeto que generó el error. (Se hereda de Exception).
Propiedad públicaStackTraceObtiene una representación de cadena de los marcos inmediatos en la pila de llamadas. (Se hereda de Exception).
Propiedad públicaTargetSiteObtiene el método que produjo la excepción actual. (Se hereda de Exception).
Arriba
  NombreDescripción
Método públicoEquals(Object)Determina si el objeto Object especificado es igual al objeto Object actual. (Se hereda de Object).
Método protegidoFinalizePermite que un objeto intente liberar recursos y realizar otras operaciones de limpieza antes de ser reclamado por la recolección de elementos no utilizados. (Se hereda de Object).
Método públicoGetBaseExceptionCuando se reemplaza en una clase derivada, devuelve la clase Exception que representa la causa principal de una o más excepciones posteriores. (Se hereda de Exception).
Método públicoGetHashCodeActúa como función hash para un tipo concreto. (Se hereda de Object).
Método públicoGetObjectDataCuando se reemplaza en una clase derivada, establece SerializationInfo con información sobre la excepción. (Se hereda de Exception).
Método públicoGetTypeObtiene el tipo en tiempo de ejecución de la instancia actual. (Se hereda de Exception).
Método protegidoMemberwiseCloneCrea una copia superficial del objeto Object actual. (Se hereda de Object).
Método públicoToStringConvierte el contenido de la excepción en una cadena. (Invalida a ExternalException..::.ToString()()()).
Arriba
  NombreDescripción
Evento protegidoSerializeObjectStateSe produce cuando se serializa una excepción para crear un objeto de estados de excepción que contiene datos serializados sobre la excepción. (Se hereda de Exception).
Arriba

Common Language Runtime transforma los valores HRESULT conocidos en excepciones de .NET, lo que permite que los objetos COM devuelvan información de error significativa a los clientes administrados. La asignación de valores HRESULT a excepciones también funciona en la otra dirección, mediante la devolución de valores HRESULT específicos a los clientes no administrados. Para obtener información detallada sobre las asignaciones, vea Cómo: Asignar resultados HRESULT y excepciones.

Cuando el motor en tiempo de ejecución encuentra un valor HRESULT desconocido (un valor HRESULT que carece de una excepción específica correspondiente), genera una instancia de la clase COMException. Esta excepción, válida para cualquier propósito, expone los mismos miembros que cualquier excepción e incluye una propiedad ErrorCode pública que contiene el valor HRESULT devuelto por el destinatario de la llamada. Si hay un mensaje de error disponible para el motor en tiempo de ejecución (que se ha obtenido a partir la interfaz IErrorInfo o del objeto Err de Visual Basic o, en algunos casos, del sistema operativo), el mensaje se devuelve al llamador. Sin embargo, si el desarrollador del componente COM no incluye un mensaje de error, el motor en tiempo de ejecución devuelve el valor HRESULT de ocho dígitos en lugar de una cadena de mensaje. El hecho de disponer de un valor HRESULT permite al llamador determinar la causa de la excepción genérica.

Aunque se puede utilizar la clase COMException para devolver valores HRESULT específicos a los clientes no administrados, es mejor producir una excepción específica de .NET que utilizar una excepción genérica. Hay que tener en cuenta que tanto los clientes administrados como los no administrados pueden utilizar el objeto .NET, y que lanzar un valor HRESULT a un llamador administrado es menos lógico que producir una excepción.

.NET Framework

Compatible con: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Compatible con: 4, 3.5 SP1

Windows 7, Windows Vista SP1 o posterior, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (no se admite Server Core), Windows Server 2008 R2 (se admite Server Core con SP1 o posterior), Windows Server 2003 SP2

.NET Framework no admite todas las versiones de todas las plataformas. Para obtener una lista de las versiones compatibles, vea Requisitos de sistema de .NET Framework.
Todos los miembros static (Shared en Visual Basic) públicos de este tipo son seguros para la ejecución de subprocesos. No se garantiza que los miembros de instancias sean seguros para la ejecución de subprocesos.
Contenido de la comunidad   ¿Qué es Community Content?
Agregar contenido nuevo RSS  Anotaciones
Processing
© 2012 Microsoft. Reservados todos los derechos. Términos de uso | Marcas Registradas | Privacidad
Page view tracker