ArgumentException 建構函式
定義
初始化 ArgumentException 類別的新執行個體。Initializes a new instance of the ArgumentException class.
多載
ArgumentException() |
初始化 ArgumentException 類別的新執行個體。Initializes a new instance of the ArgumentException class. |
ArgumentException(String) |
使用指定的錯誤訊息,初始化 ArgumentException 類別的新執行個體。Initializes a new instance of the ArgumentException class with a specified error message. |
ArgumentException(SerializationInfo, StreamingContext) |
使用序列化資料,初始化 ArgumentException 類別的新執行個體。Initializes a new instance of the ArgumentException class with serialized data. |
ArgumentException(String, Exception) |
使用指定的錯誤訊息以及造成此例外狀況的內部例外狀況的參考,初始化 ArgumentException 類別的新執行個體。Initializes a new instance of the ArgumentException class with a specified error message and a reference to the inner exception that is the cause of this exception. |
ArgumentException(String, String) |
使用指定的錯誤訊息和造成這個例外狀況的參數名稱,初始化 ArgumentException 類別的新執行個體。Initializes a new instance of the ArgumentException class with a specified error message and the name of the parameter that causes this exception. |
ArgumentException(String, String, Exception) |
使用指定的錯誤訊息、參數名稱和造成這個例外狀況原因的內部例外參考,初始化 ArgumentException 類別的新執行個體。Initializes a new instance of the ArgumentException class with a specified error message, the parameter name, and a reference to the inner exception that is the cause of this exception. |
ArgumentException()
初始化 ArgumentException 類別的新執行個體。Initializes a new instance of the ArgumentException class.
public:
ArgumentException();
public ArgumentException ();
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 takes into account the current system culture.
下表顯示 ArgumentException 執行個體的初始屬性值。The following table shows the initial property values for an instance of ArgumentException.
屬性Property | 值Value |
---|---|
InnerException | null 參考 (在 Visual Basic 中為 Nothing )。A null reference (Nothing in Visual Basic). |
Message | 當地語系化的錯誤訊息字串。The localized error message string. |
ArgumentException(String)
使用指定的錯誤訊息,初始化 ArgumentException 類別的新執行個體。Initializes a new instance of the ArgumentException class with a specified error message.
public:
ArgumentException(System::String ^ message);
public ArgumentException (string message);
new ArgumentException : string -> ArgumentException
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 takes into account the current system culture.
下表顯示 ArgumentException 執行個體的初始屬性值。The following table shows the initial property values for an instance of ArgumentException.
屬性Property | 值Value |
---|---|
InnerException | null 參考 (在 Visual Basic 中為 Nothing )。A null reference (Nothing in Visual Basic). |
Message | 錯誤訊息字串。The error message string. |
ArgumentException(SerializationInfo, StreamingContext)
使用序列化資料,初始化 ArgumentException 類別的新執行個體。Initializes a new instance of the ArgumentException class with serialized data.
protected:
ArgumentException(System::Runtime::Serialization::SerializationInfo ^ info, System::Runtime::Serialization::StreamingContext context);
protected ArgumentException (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
new ArgumentException : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> ArgumentException
Protected Sub New (info As SerializationInfo, context As StreamingContext)
參數
- info
- SerializationInfo
存放序列物件資料的物件。The object that holds the serialized object data.
- context
- StreamingContext
關於來源或目的端的內容資訊。The contextual information about the source or destination.
備註
進行還原序列化 (Deserialization) 期間會呼叫這個建構函式,以便重新構成經由資料流傳送的例外狀況物件。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.
另請參閱
ArgumentException(String, Exception)
使用指定的錯誤訊息以及造成此例外狀況的內部例外狀況的參考,初始化 ArgumentException 類別的新執行個體。Initializes a new instance of the ArgumentException class with a specified error message and a reference to the inner exception that is the cause of this exception.
public:
ArgumentException(System::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
解釋例外狀況原因的錯誤訊息。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 a null reference, the current exception is raised in a catch
block that handles the inner exception.
備註
這個函式會Message使用message
參數的值, 初始化新實例的屬性。This 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 屬性會傳回與傳入建構函式中相同的值;如果 null
屬性沒有提供內部例外值給建構函式,則傳回 InnerException。The 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.
下表顯示 ArgumentException 執行個體的初始屬性值。The following table shows the initial property values for an instance of ArgumentException.
屬性Property | 值Value |
---|---|
InnerException | 內部例外狀況參考。The inner exception reference. |
Message | 當地語系化的錯誤訊息字串。The localized error message string. |
另請參閱
ArgumentException(String, String)
使用指定的錯誤訊息和造成這個例外狀況的參數名稱,初始化 ArgumentException 類別的新執行個體。Initializes a new instance of the ArgumentException class with a specified error message and the name of the parameter that causes this exception.
public:
ArgumentException(System::String ^ message, System::String ^ paramName);
public ArgumentException (string message, string paramName);
new ArgumentException : string * string -> ArgumentException
Public Sub New (message As String, paramName As String)
參數
- message
- String
解釋例外狀況原因的錯誤訊息。The error message that explains the reason for the exception.
- paramName
- String
造成目前例外狀況的參數名稱。The name of the parameter that caused the current exception.
範例
下列程式碼範例示範如何呼叫此ArgumentException函式。The following code example demonstrates how to call the ArgumentException constructor. 這個程式碼範例是針對ArgumentException類別提供之較大範例的一部分。This code example is part of a larger example provided for the ArgumentException class.
int DivideByTwo(int num)
{
// If num is an odd number, throw an ArgumentException.
if ((num & 1) == 1)
{
throw gcnew ArgumentException("Number must be even", "num");
}
// num is even, return half of its value.
return num / 2;
}
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;
}
備註
這個函式會Message使用message
參數的值, 初始化新實例的屬性。This 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.
這個函式會ParamName使用paramName
初始化新實例的屬性。This constructor initializes the ParamName property of the new instance using paramName
. paramName
的內容必須能讓人了解。The content of paramName
is intended to be understood by humans.
下表顯示 ArgumentException 執行個體的初始屬性值。The following table shows the initial property values for an instance of ArgumentException.
屬性Property | 值Value |
---|---|
Message | 錯誤訊息字串。The error message string. |
ParamName | 參數名稱字串。The parameter name string. |
ArgumentException(String, String, Exception)
使用指定的錯誤訊息、參數名稱和造成這個例外狀況原因的內部例外參考,初始化 ArgumentException 類別的新執行個體。Initializes a new instance of the ArgumentException class with a specified error message, the parameter name, and a reference to the inner exception that is the cause of this exception.
public:
ArgumentException(System::String ^ message, System::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
解釋例外狀況原因的錯誤訊息。The error message that explains the reason for the exception.
- paramName
- String
造成目前例外狀況的參數名稱。The name of the parameter that caused the current exception.
- innerException
- Exception
做為目前例外狀況發生原因的例外狀況。The exception that is the cause of the current exception. 如果 innerException
參數不是 null 參考,目前的例外狀況會在處理內部例外的 catch
區塊中引發。If the innerException
parameter is not a null reference, the current exception is raised in a catch
block that handles the inner exception.
備註
這個函式會Message使用message
參數的值, 初始化新實例的屬性。This 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.
這個函式會ParamName使用paramName
初始化新實例的屬性。This constructor initializes the ParamName property of the new instance using paramName
. paramName
的內容必須能讓人了解。The content of paramName
is intended to be understood by humans.
被擲回以做為前一個例外狀況直接結果的例外狀況,應該在 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
屬性沒有提供內部例外值給建構函式,則傳回 InnerException。The 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.
下表顯示 ArgumentException 執行個體的初始屬性值。The following table shows the initial property values for an instance of ArgumentException.
屬性Property | 值Value |
---|---|
InnerException | 內部例外狀況參考。The inner exception reference. |
Message | 當地語系化的錯誤訊息字串。The localized error message string. |
ParamName | 參數名稱字串。The parameter name string. |