KeyNotFoundException 构造函数

定义

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

重载

KeyNotFoundException()

使用默认属性值初始化 KeyNotFoundException 类的新实例。Initializes a new instance of the KeyNotFoundException class using default property values.

KeyNotFoundException(String)

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

KeyNotFoundException(SerializationInfo, StreamingContext)

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

KeyNotFoundException(String, Exception)

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

KeyNotFoundException()

使用默认属性值初始化 KeyNotFoundException 类的新实例。Initializes a new instance of the KeyNotFoundException class using default property values.

public:
 KeyNotFoundException();
public KeyNotFoundException ();
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 "The given key was not present in the dictionary." 此消息会考虑当前系统区域性。This message takes into account the current system culture.

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

属性Property Value
InnerException nullnull.
Message 本地化的错误消息字符串。The localized error message string.

KeyNotFoundException(String)

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

public:
 KeyNotFoundException(System::String ^ message);
public KeyNotFoundException (string message);
new System.Collections.Generic.KeyNotFoundException : string -> System.Collections.Generic.KeyNotFoundException
Public Sub New (message As String)

参数

message
String

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

注解

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.

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

属性Property Value
InnerException nullnull.
Message 本地化的错误消息字符串。The localized error message string.

KeyNotFoundException(SerializationInfo, StreamingContext)

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

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

参数

info
SerializationInfo

包含有关所引发异常的序列化对象数据的 SerializationInfoThe SerializationInfo that holds the serialized object data about the exception being thrown.

context
StreamingContext

StreamingContext,它包含关于源或目标的上下文信息。The StreamingContext that contains 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.

KeyNotFoundException(String, Exception)

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

public:
 KeyNotFoundException(System::String ^ message, Exception ^ innerException);
public KeyNotFoundException (string message, Exception innerException);
new System.Collections.Generic.KeyNotFoundException : string * Exception -> System.Collections.Generic.KeyNotFoundException
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.

注解

因前一个异常而直接引发的异常应在 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 属性返回的值与传递到构造函数中的值相同;或者,如果 null 属性没有向构造函数提供内部异常值,则为 InnerExceptionThe 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.

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

属性Property Value
InnerException 内部异常引用。The inner exception reference.
Message 本地化的错误消息字符串。The localized error message string.

适用于