argument exceptionとは? わかりやすく解説

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

その他の技術情報

例外の処理とスロー



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「argument exception」の関連用語

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

   

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



argument exceptionのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2024 GRAS Group, Inc.RSS