ArgumentExceptionとは? わかりやすく解説

ArgumentException クラス

メソッドに渡された引数のいずれかが無効な場合にスローされる例外。

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public Class ArgumentException
    Inherits SystemException
    Implements ISerializable
Dim instance As ArgumentException
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public class ArgumentException : SystemException,
 ISerializable
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public ref class ArgumentException : public
 SystemException, ISerializable
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public class ArgumentException extends SystemException
 implements ISerializable
SerializableAttribute 
ComVisibleAttribute(true) 
public class ArgumentException extends
 SystemException implements ISerializable
解説解説

ArgumentException は、メソッドの呼び出し時に渡された引数の少なくとも 1 つが、呼び出されたメソッドのパラメータの仕様に一致していないとスローされます。ArgumentException のすべてのインスタンスは、無効な引数と、その引数に指定できる有効な値の範囲を説明する、わかりやすいエラーメッセージを保持する必要があります。

ArgumentException の主要な派生クラスは、ArgumentNullException と ArgumentOutOfRangeException です。これらの派生クラスは、両方とも使用できない場合以外は、ArgumentException の代わりに使用されます。たとえば、次の場合は、それぞれの派生クラスで例外をスローします。

引数を指定せずにメソッドが呼び出された場合、引数が原因ではないエラーが発生している場合は、InvalidOperationException を使用します。

ArgumentException は、値 0x80070057 を保持する HRESULT COR_E_ARGUMENT を使用します。

ArgumentException のインスタンスの初期プロパティ値の一覧については、ArgumentException コンストラクタのトピックを参照してください。

使用例使用例

ArgumentException をスローし、キャッチする方法を次の例に示します。

using System;

public sealed class App 
{
    static void Main() 
    {
        // ArgumentException is not thrown because 10 is an even number.
        Console.WriteLine("10 divided by 2 is {0}", DivideByTwo(10));
        try 
        {
             // ArgumentException is thrown because 7 is not an even
 number.
             Console.WriteLine("7 divided by 2 is {0}", DivideByTwo(7));
        }
        catch (ArgumentException)
        {
            // Show the user that 7 cannot be divided by 2.
            Console.WriteLine("7 is not divided by 2 integrally.");
        }
    }

    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;
    }
}


// This code produces the following output.
// 
// 10 divided by 2 is 5
// 7 is not divided by 2 integrally.
using namespace System;

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;
}

int main()
{
    // ArgumentException is not thrown because 10 is an even number.
    Console::WriteLine("10 divided by 2 is {0}", DivideByTwo(10));
    try
    {
        // ArgumentException is thrown because 7 is not an even number.
        Console::WriteLine("7 divided by 2 is {0}", DivideByTwo(7));
    }
    catch (ArgumentException^)
    {
        // Show the user that 7 cannot be divided by 2.
        Console::WriteLine("7 is not divided by 2 integrally.");
    }
}

// This code produces the following output.
//
// 10 divided by 2 is 5
// 7 is not divided by 2 integrally.
継承階層継承階層
System.Object
   System.Exception
     System.SystemException
      System.ArgumentException
         派生クラス
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

ArgumentException コンストラクタ ()

ArgumentException クラスの新しいインスタンスを初期化します。

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Dim instance As New ArgumentException
public ArgumentException ()
public:
ArgumentException ()
public ArgumentException ()
public function ArgumentException ()
解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ArgumentException クラス
ArgumentException メンバ
System 名前空間

ArgumentException コンストラクタ (String, String, Exception)

エラー メッセージ、パラメータ名、およびこの例外の原因である内部例外への参照を指定して、ArgumentException クラスの新しいインスタンスを初期化します。

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Sub New ( _
    message As String, _
    paramName As String, _
    innerException As Exception _
)
Dim message As String
Dim paramName As String
Dim innerException As Exception

Dim instance As New ArgumentException(message,
 paramName, innerException)
public ArgumentException (
    string message,
    string paramName,
    Exception innerException
)
public:
ArgumentException (
    String^ message, 
    String^ paramName, 
    Exception^ innerException
)
public ArgumentException (
    String message, 
    String paramName, 
    Exception innerException
)
public function ArgumentException (
    message : String, 
    paramName : String, 
    innerException : Exception
)

パラメータ

message

例外の原因を説明するエラー メッセージ。

paramName

例外の原因となったパラメータの名前。

innerException

現在の例外の原因である例外。innerException パラメータが null 参照でない場合は、内部例外を処理する catch ブロックで現在の例外が発生します。

解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

ArgumentException コンストラクタ (SerializationInfo, StreamingContext)

シリアル化したデータを使用して、ArgumentException クラスの新しいインスタンスを初期化します。

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Protected Sub New ( _
    info As SerializationInfo, _
    context As StreamingContext _
)
Dim info As SerializationInfo
Dim context As StreamingContext

Dim instance As New ArgumentException(info,
 context)
protected ArgumentException (
    SerializationInfo info,
    StreamingContext context
)
protected:
ArgumentException (
    SerializationInfo^ info, 
    StreamingContext context
)
protected ArgumentException (
    SerializationInfo info, 
    StreamingContext context
)
protected function ArgumentException (
    info : SerializationInfo, 
    context : StreamingContext
)

パラメータ

info

シリアル化されたオブジェクト データを保持するオブジェクト。

context

転送元または転送先に関するコンテキスト情報。

解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

ArgumentException コンストラクタ (String, String)

エラー メッセージ、およびこの例外の原因である引数の名前を指定して、ArgumentException クラスの新しいインスタンスを初期化します。

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Sub New ( _
    message As String, _
    paramName As String _
)
Dim message As String
Dim paramName As String

Dim instance As New ArgumentException(message,
 paramName)
public ArgumentException (
    string message,
    string paramName
)
public:
ArgumentException (
    String^ message, 
    String^ paramName
)
public ArgumentException (
    String message, 
    String paramName
)
public function ArgumentException (
    message : String, 
    paramName : String
)

パラメータ

message

例外の原因を説明するエラー メッセージ。

paramName

例外の原因となったパラメータの名前。

解説解説
使用例使用例

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;
}
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;
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ArgumentException クラス
ArgumentException メンバ
System 名前空間

ArgumentException コンストラクタ

ArgumentException クラスの新しいインスタンスを初期化します。
オーバーロードの一覧オーバーロードの一覧

参照参照

関連項目

ArgumentException クラス
ArgumentException メンバ
System 名前空間

ArgumentException コンストラクタ (String)

指定したエラー メッセージを使用して、ArgumentException クラスの新しいインスタンスを初期化します。

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ArgumentException クラス
ArgumentException メンバ
System 名前空間

ArgumentException コンストラクタ (String, Exception)

指定したエラー メッセージと、この例外の原因である内部例外への参照を使用して、ArgumentException クラスの新しいインスタンスを初期化します。

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Sub New ( _
    message As String, _
    innerException As Exception _
)
Dim message As String
Dim innerException As Exception

Dim instance As New ArgumentException(message,
 innerException)
public ArgumentException (
    string message,
    Exception innerException
)
public:
ArgumentException (
    String^ message, 
    Exception^ innerException
)
public ArgumentException (
    String message, 
    Exception innerException
)
public function ArgumentException (
    message : String, 
    innerException : Exception
)

パラメータ

message

例外の原因を説明するエラー メッセージ。

innerException

現在の例外の原因である例外。innerException パラメータが null 参照でない場合は、内部例外を処理する catch ブロックで現在の例外が発生します。

解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

ArgumentException プロパティ


ArgumentException メソッド


パブリック メソッドパブリック メソッド

プロテクト メソッドプロテクト メソッド
参照参照

関連項目

ArgumentException クラス
System 名前空間
Exception

その他の技術情報

例外の処理とスロー

ArgumentException メンバ

メソッドに渡された引数のいずれかが無効な場合にスローされる例外。

ArgumentException データ型で公開されるメンバを以下の表に示します。


パブリック コンストラクタパブリック コンストラクタ
プロテクト コンストラクタプロテクト コンストラクタ
  名前 説明
プロテクト メソッド ArgumentException オーバーロードされます。 ArgumentException クラスの新しいインスタンスを初期化します。
パブリック プロパティパブリック プロパティ
プロテクト プロパティプロテクト プロパティ
  名前 説明
プロテクト プロパティ HResult  特定の例外に割り当てられているコード化数値である HRESULT を取得または設定します。(Exception から継承されます。)
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

ArgumentException クラス
System 名前空間
Exception

その他の技術情報

例外の処理とスロー



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「ArgumentException」の関連用語

ArgumentExceptionのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



ArgumentExceptionのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS