InvalidCastException InvalidCastException InvalidCastException InvalidCastException Constructors

定义

重载

InvalidCastException() InvalidCastException() InvalidCastException()

初始化 InvalidCastException 类的新实例。Initializes a new instance of the InvalidCastException class.

InvalidCastException(String) InvalidCastException(String) InvalidCastException(String) InvalidCastException(String)

用指定的错误消息初始化 InvalidCastException 类的新实例。Initializes a new instance of the InvalidCastException class with a specified error message.

InvalidCastException(SerializationInfo, StreamingContext) InvalidCastException(SerializationInfo, StreamingContext) InvalidCastException(SerializationInfo, StreamingContext) InvalidCastException(SerializationInfo, StreamingContext)

用序列化数据初始化 InvalidCastException 类的新实例。Initializes a new instance of the InvalidCastException class with serialized data.

InvalidCastException(String, Exception) InvalidCastException(String, Exception) InvalidCastException(String, Exception) InvalidCastException(String, Exception)

使用指定的错误消息和对作为此异常原因的内部异常的引用来初始化 InvalidCastException 类的新实例。Initializes a new instance of the InvalidCastException class with a specified error message and a reference to the inner exception that is the cause of this exception.

InvalidCastException(String, Int32) InvalidCastException(String, Int32) InvalidCastException(String, Int32) InvalidCastException(String, Int32)

使用指定的消息和错误代码初始化 InvalidCastException 类的新实例。Initializes a new instance of the InvalidCastException class with a specified message and error code.

InvalidCastException() InvalidCastException() InvalidCastException()

初始化 InvalidCastException 类的新实例。Initializes a new instance of the InvalidCastException class.

public:
 InvalidCastException();
public InvalidCastException ();
Public Sub New ()

注解

此构造函数将Message新实例的属性初始化为系统提供的描述错误的消息, 例如 "无法从源类型强制转换为目标类型"。This constructor initializes the Message property of the new instance to a system-supplied message that describes the error, such as "Cannot cast from source type to destination type." 此消息将当前系统区域性考虑在内。This message takes into account the current system culture.

下表显示 InvalidCastException 的实例的初始属性值。The following table shows the initial property values for an instance of InvalidCastException.

PropertyProperty “值”Value
InnerException 空引用(在 Visual Basic 中为 Nothing)。A null reference (Nothing in Visual Basic).
Message 本地化的错误消息字符串。The localized error message string.

InvalidCastException(String) InvalidCastException(String) InvalidCastException(String) InvalidCastException(String)

用指定的错误消息初始化 InvalidCastException 类的新实例。Initializes a new instance of the InvalidCastException class with a specified error message.

public:
 InvalidCastException(System::String ^ message);
public InvalidCastException (string message);
new InvalidCastException : string -> InvalidCastException
Public Sub New (message As String)

参数

message
String String String String

描述错误的消息。The message that describes the error.

注解

此构造函数message使用Exception.Message参数初始化新异常的属性。This constructor initializes the Exception.Message property of the new exception using the message parameter. message 的内容被设计为人可理解的形式。The content of message is intended to be understood by humans. 此构造函数的调用方需要确保此字符串已针对当前系统区域性进行了本地化。The caller of this constructor is required to ensure that this string has been localized for the current system culture.

下表显示 InvalidCastException 的实例的初始属性值。The following table shows the initial property values for an instance of InvalidCastException.

PropertyProperty “值”Value
InnerException 空引用(在 Visual Basic 中为 Nothing)。A null reference (Nothing in Visual Basic).
Message 错误消息字符串。The error message string.

InvalidCastException(SerializationInfo, StreamingContext) InvalidCastException(SerializationInfo, StreamingContext) InvalidCastException(SerializationInfo, StreamingContext) InvalidCastException(SerializationInfo, StreamingContext)

用序列化数据初始化 InvalidCastException 类的新实例。Initializes a new instance of the InvalidCastException class with serialized data.

protected:
 InvalidCastException(System::Runtime::Serialization::SerializationInfo ^ info, System::Runtime::Serialization::StreamingContext context);
protected InvalidCastException (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
new InvalidCastException : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> InvalidCastException
Protected Sub New (info As SerializationInfo, context As StreamingContext)

参数

info
SerializationInfo SerializationInfo SerializationInfo SerializationInfo

承载序列化对象数据的对象。The object that holds the serialized object data.

context
StreamingContext StreamingContext StreamingContext StreamingContext

关于来源和目标的上下文信息The contextual information about the source or destination.

注解

此构造函数在反序列化过程中调用,以便重建通过流传输的异常对象。This constructor is called during deserialization to reconstitute the exception object transmitted over a stream. 有关详细信息,请参阅XML 和 SOAP 序列化For more information, see XML and SOAP Serialization.

另请参阅

InvalidCastException(String, Exception) InvalidCastException(String, Exception) InvalidCastException(String, Exception) InvalidCastException(String, Exception)

使用指定的错误消息和对作为此异常原因的内部异常的引用来初始化 InvalidCastException 类的新实例。Initializes a new instance of the InvalidCastException class with a specified error message and a reference to the inner exception that is the cause of this exception.

public:
 InvalidCastException(System::String ^ message, Exception ^ innerException);
public InvalidCastException (string message, Exception innerException);
new InvalidCastException : string * Exception -> InvalidCastException
Public Sub New (message As String, innerException As Exception)

参数

message
String String String String

解释异常原因的错误消息。The error message that explains the reason for the exception.

innerException
Exception Exception Exception Exception

导致当前异常的异常。The exception that is the cause of the current exception. 如果 innerException 参数不为 null,则当前异常将在处理内部异常的 catch 块中引发。If the innerException parameter is not null, the current exception is raised in a catch block that handles the inner exception.

注解

因前一个异常而直接引发的异常应在 InnerException 属性中包含对前一个异常的引用。An exception that is thrown as a direct result of a previous exception should include a reference to the previous exception in the InnerException property. 属性返回传递到构造函数中的相同值, 或者, 如果InnerException属性不向构造函数提供内部异常值, 则返回nullInnerExceptionThe InnerException property returns the same value that is passed into the constructor, or returns null if the InnerException property does not supply the inner exception value to the constructor.

下表显示 InvalidCastException 的实例的初始属性值。The following table shows the initial property values for an instance of InvalidCastException.

PropertyProperty “值”Value
InnerException 内部异常引用。The inner exception reference.
Message 错误消息字符串。The error message string.
另请参阅

InvalidCastException(String, Int32) InvalidCastException(String, Int32) InvalidCastException(String, Int32) InvalidCastException(String, Int32)

使用指定的消息和错误代码初始化 InvalidCastException 类的新实例。Initializes a new instance of the InvalidCastException class with a specified message and error code.

public:
 InvalidCastException(System::String ^ message, int errorCode);
public InvalidCastException (string message, int errorCode);
new InvalidCastException : string * int -> InvalidCastException
Public Sub New (message As String, errorCode As Integer)

参数

message
String String String String

指示所发生异常的原因的消息。The message that indicates the reason the exception occurred.

errorCode
Int32 Int32 Int32 Int32

与异常关联的错误代码 (HRESULT) 值。The error code (HRESULT) value associated with the exception.

注解

此构造函数message使用Exception.Message参数初始化新异常的属性。This constructor initializes the Exception.Message property of the new exception using the message parameter. message 的内容被设计为人可理解的形式。The content of message is intended to be understood by humans. 此构造函数的调用方需要确保此字符串已针对当前系统区域性进行了本地化。The caller of this constructor is required to ensure that this string has been localized for the current system culture.

此构造函数提供一个 HRESULT 值, InvalidCastException该类的继承者可以通过Exception类的 protected HResult属性访问该值。This constructor supplies an HRESULT value that is accessible to inheritors of the InvalidCastException class, via the protected HResult property of the Exception class.

下表显示 InvalidCastException 的实例的初始属性值。The following table shows the initial property values for an instance of InvalidCastException.

PropertyProperty “值”Value
InnerException 空引用(在 Visual Basic 中为 Nothing)。A null reference (Nothing in Visual Basic).
Message 错误消息字符串。The error message string.

适用于