AmbiguousMatchException Construtores
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Inicializa uma nova instância da classe AmbiguousMatchException.
Sobrecargas
| Nome | Description |
|---|---|
| AmbiguousMatchException() |
Inicializa uma nova instância da AmbiguousMatchException classe com uma cadeia de caracteres de mensagem vazia e a exceção de causa raiz definida como |
| AmbiguousMatchException(String) |
Inicializa uma nova instância da classe com sua AmbiguousMatchException cadeia de caracteres de mensagem definida como a mensagem fornecida e a exceção de causa raiz definida como |
| AmbiguousMatchException(String, Exception) |
Inicializa uma nova instância da AmbiguousMatchException classe com uma mensagem de erro especificada e uma referência à exceção interna que é a causa dessa exceção. |
AmbiguousMatchException()
- Origem:
- AmbiguousMatchException.cs
- Origem:
- AmbiguousMatchException.cs
- Origem:
- AmbiguousMatchException.cs
- Origem:
- AmbiguousMatchException.cs
- Origem:
- AmbiguousMatchException.cs
Inicializa uma nova instância da AmbiguousMatchException classe com uma cadeia de caracteres de mensagem vazia e a exceção de causa raiz definida como null.
public:
AmbiguousMatchException();
public AmbiguousMatchException();
Public Sub New ()
Comentários
AmbiguousMatchException herda de Exception. Esse construtor define as propriedades do Exception objeto, conforme mostrado na tabela a seguir.
| Propriedade | Valor |
|---|---|
| InnerException | null |
| Message | A cadeia de caracteres vazia (""). |
Confira também
Aplica-se a
AmbiguousMatchException(String)
- Origem:
- AmbiguousMatchException.cs
- Origem:
- AmbiguousMatchException.cs
- Origem:
- AmbiguousMatchException.cs
- Origem:
- AmbiguousMatchException.cs
- Origem:
- AmbiguousMatchException.cs
Inicializa uma nova instância da classe com sua AmbiguousMatchException cadeia de caracteres de mensagem definida como a mensagem fornecida e a exceção de causa raiz definida como null.
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)
Parâmetros
- message
- String
Uma cadeia de caracteres que indica o motivo pelo qual essa exceção foi gerada.
Comentários
AmbiguousMatchException herda de Exception. Esse construtor define as propriedades do Exception objeto, conforme mostrado na tabela a seguir.
| Propriedade | Valor |
|---|---|
| InnerException | null |
| Message | A message cadeia de caracteres. |
Aplica-se a
AmbiguousMatchException(String, Exception)
- Origem:
- AmbiguousMatchException.cs
- Origem:
- AmbiguousMatchException.cs
- Origem:
- AmbiguousMatchException.cs
- Origem:
- AmbiguousMatchException.cs
- Origem:
- AmbiguousMatchException.cs
Inicializa uma nova instância da AmbiguousMatchException classe com uma mensagem de erro especificada e uma referência à exceção interna que é a causa dessa exceção.
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)
Parâmetros
- message
- String
A mensagem de erro que explica o motivo da exceção.
- inner
- Exception
A exceção que é a causa da exceção atual. Se o inner parâmetro não nullfor, a exceção atual será gerada em um catch bloco que manipula a exceção interna.
Exemplos
O exemplo a seguir mostra dois métodos, cada um nomeado Mymethod. Um método usa um inteiro e o outro usa uma cadeia de caracteres. Se um inteiro for passado para Mymethod, o primeiro método será usado. Se uma cadeia de caracteres for passada, o segundo método será usado. Se não for possível determinar qual Mymethod usar, AmbiguousMatchException será gerado.
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.
Comentários
Uma exceção gerada como resultado direto de uma exceção anterior deve incluir uma referência à exceção anterior na InnerException propriedade. A InnerException propriedade retorna o mesmo valor que é passado para o construtor ou null se a InnerException propriedade não fornece o valor de exceção interna ao construtor.
A tabela a seguir mostra os valores de propriedade iniciais de uma instância de AmbiguousMatchException.
| Propriedade | Valor |
|---|---|
| InnerException | A referência de exceção interna. |
| Message | A cadeia de caracteres de mensagem de erro. |