O'Reilly logo

C# in a Nutshell by Peter Drayton, Ted Neward, Ben Albahari

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

ArgumentException class

Synopsis

This exception indicates that illegal data was passed to a method or constructor call. Note that illegal data is entirely contextual — the data may be a legitimate .NET value, but inappropriate for the use in question. Although .NET languages are type-safe in that you can’t pass a string as a parameter when an integer is expected, there is nothing to keep you from passing a null or invalid value, such as sending (2001, 13, 32) to DateTime’s constructor. However, there is no 32nd day of the 13th month of the year 2001, and if you try to initialize such a date, you’ll get an exception.

The ArgumentException class (or one of its subclasses, ArgumentNullException or ArgumentOutOfRangeException) indicates that a method argument violated such a constraint. If you need to implement this exception in your own code, consider using one of its subclasses instead, since they represent common argument exceptions.

public class ArgumentException : SystemException {
// Public Constructors
   public method ArgumentException();  
   public method ArgumentException(string message);  
   public method ArgumentException(string message, 
        Exception innerException);  
   public method ArgumentException(string message, 
        string paramName);  
   public method ArgumentException(string message, 
        string paramName, Exception innerException);  
// Protected Constructors
   protected method ArgumentException(
        System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required