See Also: ArgumentException Members
ArgumentException is thrown when a method is invoked and at least one of the passed arguments does not meet the method's parameter specification.
The Base Class Library includes three derived types:
When appropriate, use these types instead of ArgumentException.
The following example demonstrates an error that causes a ArgumentException exception to be thrown by the system.
C# Example
using System;
public class MyClass {}
public class ArgExceptionExample {
public static void Main() {
MyClass my = new MyClass();
string s = "sometext";
try {
int i = s.CompareTo(my);
}
catch (ArgumentException e) {
Console.WriteLine("Error: {0}",e);
}
}
}
The output is
Error: System.ArgumentException: Object must be of type String.