NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

AmbiguousMatchException Constructor (String, Exception)

Initializes an instance of AmbiguousMatchException with its message string set to the given message and the given root cause exception.

[Visual Basic]
Overloads Public Sub New( _
   ByVal message As String, _
   ByVal inner As Exception _
)
[C#]
public AmbiguousMatchException(
   string message,
   Exception inner
);
[C++]
public: AmbiguousMatchException(
   String* message,
   Exception* inner
);
[JScript]
public function AmbiguousMatchException(
   message : String,
   inner : Exception
);

Parameters

message
The message that indicates the reason this exception was thrown.
inner
The exception, which is the root cause of this exception.

Remarks

When handling an exception, it is sometimes helpful to have a reference to the exception(s) that caused the error to occur. You can use this constructor to create a chain of new and more meaningful exceptions with the InnerException property set to the inner exception reference. This more meaningful exception can then be thrown to the caller. Note that with this functionality it is possible to create a series of linked exceptions that terminates with the exception that was first thrown. (See Exception for more information.)

AmbiguousMatchException inherits from the SystemException. This constructor sets the properties of the AmbiguousMatchException object as follows:

Property Value
InnerException The inner exception.
Message The message string.

Example

In the example shown below, two classes are constucted, each named Mymethod. One class takes a integer and one a string. If an integer is passed to Mymethod, the first class is used. If a string is passed, the second class is used. If it cannot determine which Mymethod to use, the exception is thrown.

class Myambiguous{
   //The first overload is
typed to an Int32
   public static void
Mymethod (Int32 number){
      Console.Write("\n{0}", "I am from Int32
method");
   }
   //The second overload is
typed to a string
   public static void
Mymethod (string alpha){
      Console.Write("\n{0}", "I am from a string.");
   }
   public 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 ("Myambiguous");
 
      MethodInfo Mymethodinfo32 =
         Mytype.GetMethod("Mymethod", new Type[]{typeof(Int32)});
      MethodInfo Mymethodinfostr =
         Mytype.GetMethod("Mymethod", new Type[]{typeof(System.String)});
 
      //Invoke a method, utilizing a Int32 integer
      Mymethodinfo32.Invoke(null,new Variant[]{2});
 
      //Invoke the method utilizing a string
      Mymethodinfostr.Invoke(null,new Variant[]{"1"});
 
      //The following line causes an ambiguious exception
      MethodInfo Mymethodinfo = Mytype.GetMethod("Mymethod");
      }  // end of try block
 
      catch(System.Reflection.AmbiguousMatchException theException){
         Console.Write("\nAmbiguousMatchException message - {0}", theException.Message);
      }
      catch {
         Console.Write("\nError thrown");
      }
      return;
   }
}

Produces the following output
I am from Int32 method
I am from a string.
I am from Int32 method
I am from a string.
AmbiguousMatchException message - Ambiguous match found.

See Also

AmbiguousMatchException Class | AmbiguousMatchException Members | System.Reflection Namespace | AmbiguousMatchException Constructor Overload List | Exception