InvalidEnumArgumentException 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
當使用無效列舉值時拋出的例外。
public ref class InvalidEnumArgumentException : ArgumentException
public class InvalidEnumArgumentException : ArgumentException
[System.Serializable]
public class InvalidEnumArgumentException : ArgumentException
type InvalidEnumArgumentException = class
inherit ArgumentException
[<System.Serializable>]
type InvalidEnumArgumentException = class
inherit ArgumentException
Public Class InvalidEnumArgumentException
Inherits ArgumentException
- 繼承
- 屬性
範例
以下程式碼範例展示了如何捕捉 InvalidEnumArgumentException 例外並解讀其內容。 範例嘗試透過鑄造傳遞一個無效的枚舉值(MessageBoxButtons),作為 MessageBox.Show 方法的第三個參數。 當捕捉到例外時,範例會擷取相應的錯誤訊息、無效參數、堆疊追蹤及例外的起源。
try
{
//Attempting to pass an invalid enum value (MessageBoxButtons) to the Show method
MessageBoxButtons myButton = (MessageBoxButtons)123; // to fix use System::Windows::Forms::DialogResult::OK;
MessageBox::Show( this, "This is a message", "This is the Caption", myButton );
}
catch ( InvalidEnumArgumentException^ invE )
{
Console::WriteLine( invE->Message );
Console::WriteLine( invE->ParamName );
Console::WriteLine( invE->StackTrace );
Console::WriteLine( invE->Source );
}
try
{
// Attempts to pass an invalid enum value (MessageBoxButtons) to the Show method
MessageBoxButtons myButton = (MessageBoxButtons)123;
MessageBox.Show("This is a message", "This is the Caption", myButton);
}
catch (InvalidEnumArgumentException invE)
{
Console.WriteLine(invE.Message);
Console.WriteLine(invE.ParamName);
Console.WriteLine(invE.StackTrace);
Console.WriteLine(invE.Source);
}
Try
' Attempts to pass an invalid enum value (MessageBoxButtons) to the Show method
Dim myButton As MessageBoxButtons
myButton = CType(123, MessageBoxButtons)
MessageBox.Show("This is a message", "This is the Caption", myButton)
Catch invE As System.ComponentModel.InvalidEnumArgumentException
Console.WriteLine(invE.Message)
Console.WriteLine(invE.ParamName)
Console.WriteLine(invE.StackTrace)
Console.WriteLine(invE.Source)
End Try
備註
若你將無效列舉值傳給方法或設定屬性時,會拋出此例外。
建構函式
| 名稱 | Description |
|---|---|
| InvalidEnumArgumentException() |
初始化類別的新實例 InvalidEnumArgumentException ,且不發送訊息。 |
| InvalidEnumArgumentException(SerializationInfo, StreamingContext) |
利用指定的序列化資料與上下文初始化該類別的新 InvalidEnumArgumentException 實例。 |
| InvalidEnumArgumentException(String, Exception) |
初始化一個帶有指定詳細描述與例外的新類別實例 InvalidEnumArgumentException 。 |
| InvalidEnumArgumentException(String, Int32, Type) |
初始化一個新的類別實例 InvalidEnumArgumentException ,包含由參數、無效值及枚舉類別產生的訊息。 |
| InvalidEnumArgumentException(String) |
初始化一個新的類別實例 InvalidEnumArgumentException ,並以指定訊息進行。 |
屬性
| 名稱 | Description |
|---|---|
| Data |
取得索引鍵/值組的集合,提供例外狀況的其他使用者定義資訊。 (繼承來源 Exception) |
| HelpLink |
取得或設定與這個例外狀況相關聯的說明檔連結。 (繼承來源 Exception) |
| HResult |
取得或設定 HRESULT,這是指派給特定例外狀況的編碼數值。 (繼承來源 Exception) |
| InnerException |
會取得 Exception 造成目前例外的實例。 (繼承來源 Exception) |
| Message |
會收到錯誤訊息和參數名稱,或者如果沒有設定參數名稱,則只會收到錯誤訊息。 (繼承來源 ArgumentException) |
| ParamName |
取得導致此例外的參數名稱。 (繼承來源 ArgumentException) |
| Source |
取得或設定造成錯誤之應用程式或物件的名稱。 (繼承來源 Exception) |
| StackTrace |
取得呼叫堆疊上即時框架的字串表示。 (繼承來源 Exception) |
| TargetSite |
取得擲回目前例外狀況的方法。 (繼承來源 Exception) |
方法
| 名稱 | Description |
|---|---|
| Equals(Object) |
判斷指定的 物件是否等於目前的物件。 (繼承來源 Object) |
| GetBaseException() |
當在派生類別中被覆寫時,回傳 Exception 是一個或多個後續例外的根因。 (繼承來源 Exception) |
| GetHashCode() |
做為預設雜湊函式。 (繼承來源 Object) |
| GetObjectData(SerializationInfo, StreamingContext) |
以參數名稱及額外例外資訊設定物件。SerializationInfo (繼承來源 ArgumentException) |
| GetType() |
取得目前實例的運行時間類型。 (繼承來源 Exception) |
| MemberwiseClone() |
建立目前 Object的淺層複本。 (繼承來源 Object) |
| ToString() |
建立並傳回目前例外狀況的字串表示。 (繼承來源 Exception) |
事件
| 名稱 | Description |
|---|---|
| SerializeObjectState |
發生於例外狀況串行化以建立例外狀況狀態物件,其中包含例外狀況的串行化數據。 (繼承來源 Exception) |