AmbiguousMatchException 생성자

정의

AmbiguousMatchException 클래스의 새 인스턴스를 초기화합니다.

오버로드

AmbiguousMatchException()

빈 메시지 문자열과 null로 설정된 근본 원인 예외를 사용하여 AmbiguousMatchException 클래스의 새 인스턴스를 초기화합니다.

AmbiguousMatchException(String)

메시지 문자열을 제공된 메시지로 설정하고 근본 원인 예외를 null로 설정하여 AmbiguousMatchException 클래스의 새 인스턴스를 초기화합니다.

AmbiguousMatchException(String, Exception)

지정된 오류 메시지와 해당 예외의 원인인 내부 예외에 대한 참조를 사용하여 AmbiguousMatchException 클래스의 새 인스턴스를 초기화합니다.

AmbiguousMatchException()

Source:
AmbiguousMatchException.cs
Source:
AmbiguousMatchException.cs
Source:
AmbiguousMatchException.cs

빈 메시지 문자열과 null로 설정된 근본 원인 예외를 사용하여 AmbiguousMatchException 클래스의 새 인스턴스를 초기화합니다.

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

설명

AmbiguousMatchExceptionException에서 상속됩니다. 이 생성자의 속성을 설정 합니다 Exception 다음 표에 나와 있는 것 처럼 개체입니다.

속성
InnerException null
Message 빈 문자열("")입니다.

추가 정보

적용 대상

AmbiguousMatchException(String)

Source:
AmbiguousMatchException.cs
Source:
AmbiguousMatchException.cs
Source:
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

이 예외가 throw된 원인을 나타내는 문자열입니다.

설명

AmbiguousMatchExceptionException에서 상속됩니다. 이 생성자의 속성을 설정 합니다 Exception 다음 표에 나와 있는 것 처럼 개체입니다.

속성
InnerException null
Message message 문자열입니다.

적용 대상

AmbiguousMatchException(String, Exception)

Source:
AmbiguousMatchException.cs
Source:
AmbiguousMatchException.cs
Source:
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두 메서드를 보여 줍니다. 한 메서드는 정수, 다른 메서드는 문자열을 사용합니다. 정수 가 에 전달 Mymethod되면 첫 번째 메서드가 사용됩니다. 문자열이 전달되면 두 번째 메서드가 사용됩니다. 사용할 AmbiguousMatchException 것을 확인할 Mymethod 수 없으면 이 throw됩니다.

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.

설명

이전 예외의 직접적인 결과로 throw되는 예외의 InnerException 속성에는 이전 예외에 대한 참조가 들어 있어야 합니다. InnerException 속성은 생성자로 전달되는 값과 같은 값을 반환하거나, InnerException 속성이 생성자에 내부 예외 값을 제공하지 않는 경우 null을 반환합니다.

다음 표에는 AmbiguousMatchException의 인스턴스의 초기 속성 값이 나와 있습니다.

속성
InnerException 내부 예외 참조
Message 오류 메시지 문자열입니다.

추가 정보

적용 대상