BCL mscorlib [00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 ] 1.0.5000.0 2.0.0.0 4.0.0.0 All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe. System.SystemException System.Runtime.InteropServices.ComVisible(true)

The following example demonstrates an error that causes a exception to be thrown by the system.

`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.

at System.String.CompareTo(Object value)

at ArgExceptionExample.Main()

is thrown when a method is invoked and at least one of the passed arguments does not meet the parameter specification of the called method. All instances of should carry a meaningful error message describing the invalid argument, as well as the expected range of values for the argument.

The primary derived classes of are and . These derived classes should be used instead of , except in situations where neither of the derived classes is acceptable. For example, exceptions should be thrown by:

whenever null is passed to a method that does not accept it as a valid argument.

when the value of an argument is outside the range of acceptable values; for example, when the value "46" is passed as the month argument during the creation of a .

If the method call does not have any argument or if the failure does not involve the arguments themselves, then should be used.

uses the HRESULT COR_E_ARGUMENT, which has the value 0x80070057.

For a list of initial property values for an instance of , see the constructors.

The exception that is thrown when one of the arguments provided to a method is not valid.

- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0

  This constructor initializes the property of the new instance to a system-supplied message that describes the error, such as "An invalid argument was specified." This message takes into account the current system culture.

  The following table shows the initial property values for an instance of .

  Property

  Value

  A null reference (Nothing in Visual Basic).

  The localized error message string.

  Initializes a new instance of the class.

  0
- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0

  This constructor initializes the property of the new instance to a system-supplied message that describes the error, such as "An invalid argument was specified." This message takes into account the current system culture.

  The following table shows the initial property values for an instance of .

  Property

  Value

  A null reference (Nothing in Visual Basic).

  The error message string.

  Initializes a new instance of the class with a specified error message.

  The error message that explains the reason for the exception.
  0
- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0

  This constructor is called during deserialization to reconstitute the exception object transmitted over a stream. For more information, see XML and Soap Serialization.

  Initializes a new instance of the class with serialized data.

  The object that holds the serialized object data.
  The contextual information about the source or destination.
- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0

  This constructor initializes the property of the new instance using the value of the parameter. The content of the parameter is intended to be understood by humans. The caller of this constructor is required to ensure that this string has been localized for the current system culture.

  An exception that is thrown as a direct result of a previous exception should include a reference to the previous exception in the property. The property returns the same value that is passed into the constructor, or null if the property does not supply the inner exception value to the constructor.

  The following table shows the initial property values for an instance of .

  Property

  Value

  The inner exception reference.

  Message

  The error message string.

  Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception.

  The error message that explains the reason for the exception.
  The exception that is the cause of the current exception. If the parameter is not a null reference, the current exception is raised in a catch block that handles the inner exception.
  0
- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0

  This constructor initializes the property of the new instance using the value of the parameter. The content of the parameter is intended to be understood by humans. The caller of this constructor is required to ensure that this string has been localized for the current system culture.

  This constructor initializes the property of the new instance using . The content of is intended to be understood by humans.

  The following table shows the initial property values for an instance of .

  Property

  Value

  The error message string.

  The parameter name string.

  Initializes a new instance of the class with a specified error message and the name of the parameter that causes this exception.

  The error message that explains the reason for the exception.
  The name of the parameter that caused the current exception.
  0
- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0

  This constructor initializes the property of the new instance using the value of the parameter. The content of the parameter is intended to be understood by humans. The caller of this constructor is required to ensure that this string has been localized for the current system culture.

  This constructor initializes the property of the new instance using . The content of is intended to be understood by humans.

  An exception that is thrown as a direct result of a previous exception should include a reference to the previous exception in the property. The property returns the same value that is passed into the constructor, or null if the property does not supply the inner exception value to the constructor.

  The following table shows the initial property values for an instance of .

  Property

  Value

  The inner exception reference.

  Message

  The error message string.

  ParamName

  The parameter name string.

  Initializes a new instance of the class with a specified error message, the parameter name, and a reference to the inner exception that is the cause of this exception.

  The error message that explains the reason for the exception.
  The name of the parameter that caused the current exception.
  The exception that is the cause of the current exception. If the parameter is not a null reference, the current exception is raised in a catch block that handles the inner exception.
  0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void `` ``

  sets a with all the exception object data targeted for serialization. During deserialization, the exception object is reconstituted from the transmitted over the stream.

  For more information, see .

  Sets the object with the parameter name and additional exception information.

  The object that holds the serialized object data. The contextual information about the source or destination.
- Property
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.String

  A containing the error message with appended, if it in not .

  This property overrides . The error message should be localized.

  Gets the error message and the parameter name, or only the error message if no parameter name is set.

- Property
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.String

  A that contains the name of the parameter that caused the current Exception, or if no value was specified to the constructor for the current instance.

  Every should carry the name of the parameter that causes this exception.

  This property is read-only, and returns the same value as was passed into the constructor. Overriding methods should be used solely to customize the format of the parameter name.

  The parameter name should not be translated for localization purposes.

  Gets the name of the parameter that causes this exception.

  0
0