AmbiguousMatchException コンストラクター

定義

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

オーバーロード

AmbiguousMatchException()

空のメッセージ文字列を使用し、主要原因となる例外を null に設定して、AmbiguousMatchException クラスの新しいインスタンスを初期化します。

AmbiguousMatchException(String)

メッセージ文字列セットを特定のメッセージに、主要原因となる例外を null に設定して、AmbiguousMatchException クラスの新しいインスタンスを初期化します。

AmbiguousMatchException(String, Exception)

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

AmbiguousMatchException()

ソース:
AmbiguousMatchException.cs
ソース:
AmbiguousMatchException.cs
ソース:
AmbiguousMatchException.cs

空のメッセージ文字列を使用し、主要原因となる例外を null に設定して、AmbiguousMatchException クラスの新しいインスタンスを初期化します。

public:
 AmbiguousMatchException();
public AmbiguousMatchException ();
Public Sub New ()

注釈

AmbiguousMatchException は、Exception から継承されます。 このコンストラクターは、次の表に Exception 示すように、 オブジェクトのプロパティを設定します。

プロパティ
InnerException null
Message 空の文字列 ("")。

こちらもご覧ください

適用対象

AmbiguousMatchException(String)

ソース:
AmbiguousMatchException.cs
ソース:
AmbiguousMatchException.cs
ソース:
AmbiguousMatchException.cs

メッセージ文字列セットを特定のメッセージに、主要原因となる例外を null に設定して、AmbiguousMatchException クラスの新しいインスタンスを初期化します。

public:
 AmbiguousMatchException(System::String ^ message);
public AmbiguousMatchException (string message);
public AmbiguousMatchException (string? message);
new System.Reflection.AmbiguousMatchException : string -> System.Reflection.AmbiguousMatchException
Public Sub New (message As String)

パラメーター

message
String

この例外がスローされた原因を示す文字列。

注釈

AmbiguousMatchException は、Exception から継承されます。 このコンストラクターは、次の表に Exception 示すように、 オブジェクトのプロパティを設定します。

プロパティ
InnerException null
Message message文字列。

適用対象

AmbiguousMatchException(String, Exception)

ソース:
AmbiguousMatchException.cs
ソース:
AmbiguousMatchException.cs
ソース:
AmbiguousMatchException.cs

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

public:
 AmbiguousMatchException(System::String ^ message, Exception ^ inner);
public AmbiguousMatchException (string message, Exception inner);
public AmbiguousMatchException (string? message, Exception? inner);
new System.Reflection.AmbiguousMatchException : string * Exception -> System.Reflection.AmbiguousMatchException
Public Sub New (message As String, inner As Exception)

パラメーター

message
String

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

inner
Exception

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

次の例は、 という名前 Mymethodの 2 つのメソッドを示しています。 1 つのメソッドは整数を受け取り、もう 1 つのメソッドは文字列を受け取ります。 に整数が渡される場合は、最初のメソッドが使用されます Mymethod。 文字列が渡された場合は、2 番目のメソッドが使用されます。 どちらを使用するかを Mymethod 決定できない場合は、 AmbiguousMatchException がスローされます。

using namespace System;
using namespace System::Reflection;

namespace Ambiguity
{
    ref class Myambiguous
    {
    public:

        //The first overload is typed to an Int32
        static void Mymethod(Int32 number)
        {
            Console::WriteLine("I am from 'Int32' method");
        }

        //The second overload is typed to a String^
        static void Mymethod(String^ alpha)
        {
            Console::WriteLine("I am from 'String^' method.");
        }

        static void Main()
        {
            try
            {
                //The following does not cause as exception
                Mymethod(2);    // goes to Mymethod (Int32)
                Mymethod("3");  // goes to Mymethod (String*)
                Type^ Mytype = Type::GetType("Ambiguity.Myambiguous");
                array<Type^>^temp0 = {Int32::typeid};
                MethodInfo^ Mymethodinfo32 = Mytype->GetMethod("Mymethod", temp0);
                array<Type^>^temp1 = {System::String::typeid};
                MethodInfo^ Mymethodinfostr = Mytype->GetMethod("Mymethod", temp1);

                //Invoke a method, utilizing a Int32 integer
                array<Object^>^temp2 = {2};
                Mymethodinfo32->Invoke(nullptr, temp2);

                //Invoke the method utilizing a String^
                array<Object^>^temp3 = {"1"};
                Mymethodinfostr->Invoke(nullptr, temp3);

                //The following line causes an ambiguous exception
                MethodInfo^ Mymethodinfo = Mytype->GetMethod("Mymethod");
            }
            catch (AmbiguousMatchException^ ex)
            {
                Console::WriteLine("\n{0}\n{1}", ex->GetType()->FullName, ex->Message);
            }
            catch (...)
            {
                Console::WriteLine("\nSome other exception.");
            }

            return;
        }
    };
}

int main()
{
    Ambiguity::Myambiguous::Main();
}

//This code produces the following output:
//
// I am from 'Int32' method
// I am from 'String^' method.
// I am from 'Int32' method
// I am from 'String^' method.
//
// System.Reflection.AmbiguousMatchException
// Ambiguous match found.
using System;
using System.Reflection;

namespace Ambiguity
{
    class Myambiguous
    {
        //The first overload is typed to an int
        public static void Mymethod(int number)
        {
           Console.WriteLine("I am from 'int' method");
        }

        //The second overload is typed to a string
        public static void Mymethod(string alpha)
        {
            Console.WriteLine("I am from 'string' method.");
        }

        public static void Main()
        {
            try
            {
                //The following does not cause as exception
                Mymethod(2);    // goes to Mymethod(int)
                Mymethod("3");  // goes to Mymethod(string)

                Type Mytype = Type.GetType("Ambiguity.Myambiguous");

                MethodInfo Mymethodinfo32 = Mytype.GetMethod("Mymethod", new Type[]{typeof(int)});
                MethodInfo Mymethodinfostr = Mytype.GetMethod("Mymethod", new Type[]{typeof(System.String)});

                //Invoke a method, utilizing a int integer
                Mymethodinfo32.Invoke(null, new Object[]{2});

                //Invoke the method utilizing a string
                Mymethodinfostr.Invoke(null, new Object[]{"1"});

                //The following line causes an ambiguious exception
                MethodInfo Mymethodinfo = Mytype.GetMethod("Mymethod");
            }   // end of try block
            catch (AmbiguousMatchException ex)
            {
                Console.WriteLine("\n{0}\n{1}", ex.GetType().FullName, ex.Message);
            }
            catch
            {
                Console.WriteLine("\nSome other exception.");
            }
            return;
        }
    }
}

//This code produces the following output:
//
// I am from 'int' method
// I am from 'string' method.
// I am from 'int' method
// I am from 'string' method.

// System.Reflection.AmbiguousMatchException
// Ambiguous match found.
Imports System.Reflection

Namespace Ambiguity
    Class Myambiguous

        'The first overload is typed to an Int32
        Overloads Public Shared Sub Mymethod(number As Int32)
            Console.WriteLine("I am from 'Int32' method")
        End Sub

        'The second overload is typed to a string
        Overloads Public Shared Sub Mymethod(alpha As String)
            Console.WriteLine("I am from 'string' method.")
        End Sub

        Public Shared Sub Main()
            Try
                'The following does not cause as exception
                Mymethod(2) ' goes to Mymethod Int32)
                Mymethod("3") ' goes to Mymethod(string)
                Dim Mytype As Type = Type.GetType("Ambiguity.Myambiguous")

                Dim Mymethodinfo32 As MethodInfo = Mytype.GetMethod("Mymethod", New Type() {GetType(Int32)})
                Dim Mymethodinfostr As MethodInfo = Mytype.GetMethod("Mymethod", New Type() {GetType(System.String)})

                'Invoke a method, utilizing a Int32 integer
                Mymethodinfo32.Invoke(Nothing, New Object() {2})

                'Invoke the method utilizing a string
                Mymethodinfostr.Invoke(Nothing, New Object() {"1"})

                'The following line causes an ambiguious exception
                Dim Mymethodinfo As MethodInfo = Mytype.GetMethod("Mymethod")
                ' end of try block
            Catch ex As AmbiguousMatchException
                Console.WriteLine(Environment.NewLine + "{0}" + Environment.NewLine + "{1}", ex.GetType().FullName, ex.Message)
            Catch
                Console.WriteLine(Environment.NewLine + "Some other exception.")
            End Try
            Return
        End Sub
    End Class
End Namespace
' This code produces the following output:
'
' I am from 'Int32' method
' I am from 'string' method.
' I am from 'Int32' method
' I am from 'string' method.
'
' System.Reflection.AmbiguousMatchException
' Ambiguous match found.

注釈

前の例外の直接の結果としてスローされる例外については、InnerException プロパティに、前の例外への参照を含める必要があります。 InnerException プロパティは、コンストラクターに渡されるのと同じ値を返します。または、InnerException プロパティがコンストラクターに内部例外値を提供しない場合には null を返します。

次の表に、AmbiguousMatchException のインスタンスに対するプロパティの初期値を示します。

プロパティ [値]
InnerException 内部例外の参照。
Message エラー メッセージ文字列。

こちらもご覧ください

適用対象