InvalidEnumArgumentException クラス
アセンブリ: System (system.dll 内)


この例外は、無効な列挙値をメソッドに渡した場合や、プロパティの設定時にスローされます。
![]() |
---|
このクラスに適用される HostProtectionAttribute 属性の Resources プロパティの値は、SharedState です。HostProtectionAttribute は、デスクトップ アプリケーション (一般的には、アイコンをダブルクリック、コマンドを入力、またはブラウザに URL を入力して起動するアプリケーション) には影響しません。詳細については、HostProtectionAttribute クラスのトピックまたは「SQL Server プログラミングとホスト保護属性」を参照してください。 |

InvalidEnumArgumentException 例外をキャッチし、その内容を解釈する方法を次の例に示します。この例では、MessageBox.Show メソッドの 3 番目の引数として、キャストを使用して無効な列挙値 (MessageBoxButtons) を渡します。例外をキャッチしたときに、この例はそれぞれのエラー メッセージ、無効なパラメータ、スタック トレース、および例外の発生源をフェッチします。
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
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 { //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.get_Message()); Console.WriteLine(invE.get_ParamName()); Console.WriteLine(invE.get_StackTrace()); Console.WriteLine(invE.get_Source()); }

System.Exception
System.SystemException
System.ArgumentException
System.ComponentModel.InvalidEnumArgumentException


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- InvalidEnumArgumentException クラスのページへのリンク