ArgumentException 构造函数
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
初始化 ArgumentException 类的新实例。
重载
| 名称 | 说明 |
|---|---|
| ArgumentException() |
初始化 ArgumentException 类的新实例。 |
| ArgumentException(String) |
使用指定的错误消息初始化类的新实例 ArgumentException 。 |
| ArgumentException(SerializationInfo, StreamingContext) |
已过时.
使用序列化数据初始化类的新实例 ArgumentException 。 |
| ArgumentException(String, Exception) |
使用指定的错误消息和对作为此异常原因的内部异常的引用初始化类的新实例 ArgumentException 。 |
| ArgumentException(String, String) |
使用指定的错误消息和导致此异常的参数的名称初始化类的新实例 ArgumentException 。 |
| ArgumentException(String, String, Exception) |
使用指定的错误消息、参数名称和对作为此异常原因的内部异常的引用初始化类的新实例 ArgumentException 。 |
ArgumentException()
- Source:
- ArgumentException.cs
- Source:
- ArgumentException.cs
- Source:
- ArgumentException.cs
- Source:
- ArgumentException.cs
- Source:
- ArgumentException.cs
初始化 ArgumentException 类的新实例。
public:
ArgumentException();
public ArgumentException();
Public Sub New ()
注解
此构造函数将 Message 新实例的属性初始化为描述错误的系统提供的消息,例如“指定了无效参数”。此消息将考虑当前系统区域性。
下表显示了 ArgumentException实例的初始属性值。
| 财产 | 价值 |
|---|---|
| InnerException | Null 引用(Nothing 在 Visual Basic 中)。 |
| Message | 本地化的错误消息字符串。 |
适用于
ArgumentException(String)
- Source:
- ArgumentException.cs
- Source:
- ArgumentException.cs
- Source:
- ArgumentException.cs
- Source:
- ArgumentException.cs
- Source:
- ArgumentException.cs
使用指定的错误消息初始化类的新实例 ArgumentException 。
public:
ArgumentException(System::String ^ message);
public ArgumentException(string message);
public ArgumentException(string? message);
new ArgumentException : string -> ArgumentException
Public Sub New (message As String)
参数
- message
- String
说明异常原因的错误消息。
注解
此构造函数将 Message 新实例的属性初始化为描述错误的系统提供的消息,例如“指定了无效参数”。此消息将考虑当前系统区域性。
下表显示了 ArgumentException实例的初始属性值。
| 财产 | 价值 |
|---|---|
| InnerException | Null 引用(Nothing 在 Visual Basic 中)。 |
| Message | 错误消息字符串。 |
适用于
ArgumentException(SerializationInfo, StreamingContext)
- Source:
- ArgumentException.cs
- Source:
- ArgumentException.cs
- Source:
- ArgumentException.cs
- Source:
- ArgumentException.cs
- Source:
- ArgumentException.cs
注意
This API supports obsolete formatter-based serialization. It should not be called or extended by application code.
使用序列化数据初始化类的新实例 ArgumentException 。
protected:
ArgumentException(System::Runtime::Serialization::SerializationInfo ^ info, System::Runtime::Serialization::StreamingContext context);
[System.Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId="SYSLIB0051", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
protected ArgumentException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
protected ArgumentException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
[<System.Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId="SYSLIB0051", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
new ArgumentException : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> ArgumentException
new ArgumentException : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> ArgumentException
Protected Sub New (info As SerializationInfo, context As StreamingContext)
参数
- info
- SerializationInfo
保存序列化对象数据的对象。
- context
- StreamingContext
有关源或目标的上下文信息。
- 属性
注解
在反序列化期间调用此构造函数以重新构造通过流传输的异常对象。 有关详细信息,请参阅 XML 和 SOAP 序列化。
另请参阅
适用于
ArgumentException(String, Exception)
- Source:
- ArgumentException.cs
- Source:
- ArgumentException.cs
- Source:
- ArgumentException.cs
- Source:
- ArgumentException.cs
- Source:
- ArgumentException.cs
使用指定的错误消息和对作为此异常原因的内部异常的引用初始化类的新实例 ArgumentException 。
public:
ArgumentException(System::String ^ message, Exception ^ innerException);
public ArgumentException(string message, Exception innerException);
public ArgumentException(string? message, Exception? innerException);
new ArgumentException : string * Exception -> ArgumentException
Public Sub New (message As String, innerException As Exception)
参数
- message
- String
说明异常原因的错误消息。
- innerException
- Exception
是当前异常原因的异常。
innerException如果参数不是 null 引用,则当前异常在处理内部异常的块中catch引发。
注解
此构造函数使用参数的值初始化 Message 新实例的属性 message 。 参数的内容 message 旨在由人类理解。 此构造函数的调用方必须确保此字符串已本地化为当前系统区域性。
作为上一个异常的直接结果引发的异常应包括对 InnerException 属性中上一个异常的引用。
InnerException 属性返回传入构造函数的相同值,或者如果 null 属性未向构造函数提供内部异常值,则返回 InnerException。
下表显示了 ArgumentException实例的初始属性值。
| 财产 | 价值 |
|---|---|
| InnerException | 内部异常引用。 |
| Message | 本地化的错误消息字符串。 |
另请参阅
适用于
ArgumentException(String, String)
- Source:
- ArgumentException.cs
- Source:
- ArgumentException.cs
- Source:
- ArgumentException.cs
- Source:
- ArgumentException.cs
- Source:
- ArgumentException.cs
使用指定的错误消息和导致此异常的参数的名称初始化类的新实例 ArgumentException 。
public:
ArgumentException(System::String ^ message, System::String ^ paramName);
public ArgumentException(string message, string paramName);
public ArgumentException(string? message, string? paramName);
new ArgumentException : string * string -> ArgumentException
Public Sub New (message As String, paramName As String)
参数
- message
- String
说明异常原因的错误消息。
- paramName
- String
导致当前异常的参数的名称。
示例
下面的代码示例演示如何调用 ArgumentException 构造函数。 该代码示例是 ArgumentException 类中的一个较大示例的一部分。
static int DivideByTwo(int num)
{
// If num is an odd number, throw an ArgumentException.
if ((num & 1) == 1)
throw new ArgumentException("Number must be even", "num");
// num is even, return half of its value.
return num / 2;
}
let divideByTwo num =
// If num is an odd number, raise an ArgumentException.
if num % 2 = 1 then
raise (ArgumentException("num", "Number must be even"))
// num is even, return half of its value.
num / 2;
注解
此构造函数使用参数的值初始化 Message 新实例的属性 message 。 参数的内容 message 旨在由人类理解。 此构造函数的调用方必须确保此字符串已本地化为当前系统区域性。
此构造函数使用 ParamName.. 初始化paramName新实例的属性。 内容 paramName 旨在由人类理解。
下表显示了 ArgumentException实例的初始属性值。
| 财产 | 价值 |
|---|---|
| Message | 错误消息字符串。 |
| ParamName | 参数名称字符串。 |
适用于
ArgumentException(String, String, Exception)
- Source:
- ArgumentException.cs
- Source:
- ArgumentException.cs
- Source:
- ArgumentException.cs
- Source:
- ArgumentException.cs
- Source:
- ArgumentException.cs
使用指定的错误消息、参数名称和对作为此异常原因的内部异常的引用初始化类的新实例 ArgumentException 。
public:
ArgumentException(System::String ^ message, System::String ^ paramName, Exception ^ innerException);
public ArgumentException(string message, string paramName, Exception innerException);
public ArgumentException(string? message, string? paramName, Exception? innerException);
new ArgumentException : string * string * Exception -> ArgumentException
Public Sub New (message As String, paramName As String, innerException As Exception)
参数
- message
- String
说明异常原因的错误消息。
- paramName
- String
导致当前异常的参数的名称。
- innerException
- Exception
是当前异常原因的异常。
innerException如果参数不是 null 引用,则当前异常在处理内部异常的块中catch引发。
注解
此构造函数使用参数的值初始化 Message 新实例的属性 message 。 参数的内容 message 旨在由人类理解。 此构造函数的调用方必须确保此字符串已本地化为当前系统区域性。
此构造函数使用 ParamName.. 初始化paramName新实例的属性。 内容 paramName 旨在由人类理解。
作为上一个异常的直接结果引发的异常应包括对 InnerException 属性中上一个异常的引用。
InnerException 属性返回传入构造函数的相同值,或者如果 null 属性未向构造函数提供内部异常值,则返回 InnerException。
下表显示了 ArgumentException实例的初始属性值。
| 财产 | 价值 |
|---|---|
| InnerException | 内部异常引用。 |
| Message | 本地化的错误消息字符串。 |
| ParamName | 参数名称字符串。 |