InvalidDataException 构造函数

定义

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

重载

InvalidDataException()

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

InvalidDataException(String)

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

InvalidDataException(String, Exception)

用对作为此异常原因的内部异常的引用初始化 InvalidDataException 类的新实例。Initializes a new instance of the InvalidDataException class with a reference to the inner exception that is the cause of this exception.

注解

InvalidDataException当在数据流中检测到无效数据时,将引发,如以下情况中所示:An InvalidDataException is thrown when invalid data is detected in the data stream, such as in the following situations:

  • 带分隔符的文本文件中的一行数据不具有预期的字段数。A row of data in a delimited text file does not have the expected number of fields.

  • 尝试读取已损坏的二进制文件(如文字处理文档)。An attempt is made to read a binary file, such as word processing document, that has become corrupted.

  • 尝试从格式无效的解压缩流中读取字节。An attempt is made to read bytes from a decompression stream that has an invalid format.

InvalidDataException()

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

public:
 InvalidDataException();
public InvalidDataException ();
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 "An invalid argument was specified." 此消息基于当前系统区域性进行了本地化。This message is localized based on the current system culture.

适用于

InvalidDataException(String)

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

public:
 InvalidDataException(System::String ^ message);
public InvalidDataException (string message);
public InvalidDataException (string? message);
new System.IO.InvalidDataException : string -> System.IO.InvalidDataException
Public Sub New (message As String)

参数

message
String

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

注解

此构造函数将 Message 新实例的属性初始化为系统提供的描述错误的消息,如 "指定了无效的参数。"This constructor initializes the Message property of the new instance to a system-supplied message that describes the error, such as "An invalid argument was specified." 此消息基于当前系统区域性进行了本地化。This message is localized based on the current system culture.

适用于

InvalidDataException(String, Exception)

用对作为此异常原因的内部异常的引用初始化 InvalidDataException 类的新实例。Initializes a new instance of the InvalidDataException class with a reference to the inner exception that is the cause of this exception.

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

参数

message
String

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

innerException
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.

注解

此构造函数 Message 使用参数的值初始化新实例的属性 messageThis constructor initializes the Message property of the new instance using the value of the message parameter. message 参数的内容应为人所理解。The content of the message parameter 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.

因前一个异常而直接引发的异常应在 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 属性将返回传递给构造函数的同一值;如果 InnerException 属性不向构造函数提供内部异常值,则返回 nullThe InnerException property returns the same value that is passed into the constructor, or null if the InnerException property does not supply the inner exception value to the constructor.

适用于