Partager via


AmbiguousMatchException Constructeurs

Définition

Initialise une nouvelle instance de la classe AmbiguousMatchException.

Surcharges

Nom Description
AmbiguousMatchException()

Initialise une nouvelle instance de la AmbiguousMatchException classe avec une chaîne de message vide et l’exception de cause racine définie nullsur .

AmbiguousMatchException(String)

Initialise une nouvelle instance de la AmbiguousMatchException classe avec sa chaîne de message définie sur le message donné et l’exception de cause racine définie nullsur .

AmbiguousMatchException(String, Exception)

Initialise une nouvelle instance de la AmbiguousMatchException classe avec un message d’erreur spécifié et une référence à l’exception interne qui est la cause de cette exception.

AmbiguousMatchException()

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

Initialise une nouvelle instance de la AmbiguousMatchException classe avec une chaîne de message vide et l’exception de cause racine définie nullsur .

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

Remarques

AmbiguousMatchException hérite de Exception. Ce constructeur définit les propriétés de l’objet Exception , comme indiqué dans le tableau suivant.

Propriété Valeur
InnerException null
Message Chaîne vide («  »).

Voir aussi

S’applique à

AmbiguousMatchException(String)

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

Initialise une nouvelle instance de la AmbiguousMatchException classe avec sa chaîne de message définie sur le message donné et l’exception de cause racine définie nullsur .

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)

Paramètres

message
String

Chaîne indiquant la raison pour laquelle cette exception a été levée.

Remarques

AmbiguousMatchException hérite de Exception. Ce constructeur définit les propriétés de l’objet Exception , comme indiqué dans le tableau suivant.

Propriété Valeur
InnerException null
Message Chaîne message .

S’applique à

AmbiguousMatchException(String, Exception)

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

Initialise une nouvelle instance de la AmbiguousMatchException classe avec un message d’erreur spécifié et une référence à l’exception interne qui est la cause de cette exception.

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)

Paramètres

message
String

Message d’erreur qui explique la raison de l’exception.

inner
Exception

Exception qui est la cause de l’exception actuelle. Si le inner paramètre n’est pas null, l’exception actuelle est levée dans un catch bloc qui gère l’exception interne.

Exemples

L’exemple suivant montre deux méthodes, chacune nommée Mymethod. Une méthode prend un entier et l’autre prend une chaîne. Si un entier est passé à Mymethod, la première méthode est utilisée. Si une chaîne est passée, la deuxième méthode est utilisée. Si elle ne peut pas être déterminée à Mymethod utiliser, AmbiguousMatchException elle est levée.

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.

Remarques

Une exception levée en conséquence directe d’une exception précédente doit inclure une référence à l’exception précédente dans la InnerException propriété. La InnerException propriété retourne la même valeur que celle passée dans le constructeur, ou null si la InnerException propriété ne fournit pas la valeur d’exception interne au constructeur.

Le tableau suivant présente les valeurs de propriété initiales d’une instance de AmbiguousMatchException.

Propriété Valeur
InnerException Référence d’exception interne.
Message Chaîne de message d’erreur.

Voir aussi

S’applique à