public class ArgumentOutOfRangeException : ArgumentException
Object
Exception
SystemException
ArgumentException
ArgumentOutOfRangeException
mscorlib
BCL
Represents the error that occurs when an argument passed to a method is invalid because it is outside the allowable range of values as specified by the method.
[Note: ArgumentOutOfRangeException is thrown when a method is invoked and at least one of the arguments passed to the method is notnull
and does not contain a valid value.ArgumentOutOfRangeException behaves identically to ArgumentException. It is provided so that application code can differentiate between exceptions caused by invalid arguments that are not
null
, and exceptions caused bynull
arguments. For errors caused bynull
arguments, see ArgumentNullException.]
The following example demonstrates an error that causes the Array class to throw a ArgumentOutOfRangeException exception.
using System; class ArgOutOfRangeExample { public static void Main() { int[] array1 = {0,0}; int[] array2 = {0,0}; try { Array.Copy(array1,array2,-1); } catch (ArgumentOutOfRangeException e) { Console.WriteLine("Error: {0}",e); } } }The output is
Error: System.ArgumentOutOfRangeException: Non-negative number required.
Parameter name: length
at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length)
at ArgOutOfRangeExample.Main()
System Namespace
ArgumentOutOfRangeException Constructors
ArgumentOutOfRangeException() Constructor
ArgumentOutOfRangeException(System.String) Constructor
ArgumentOutOfRangeException(System.String, System.String) Constructor
ArgumentOutOfRangeException(System.String, System.Object, System.String) Constructor
ArgumentOutOfRangeException Properties
ArgumentOutOfRangeException.ActualValue Property
ArgumentOutOfRangeException.Message Property
public ArgumentOutOfRangeException();
Constructs and initializes a new instance of the ArgumentOutOfRangeException class.
This constructor initializes the System.ArgumentOutOfRangeException.Message property of the new instance to a system-supplied message that describes the error, such as "Non-negative number required." This message takes into account the current system culture.The System.ArgumentOutOfRangeException.ParamName and System.ArgumentOutOfRangeException.ActualValue properties are initialized to
null
.
System.ArgumentOutOfRangeException Class, System Namespace
public ArgumentOutOfRangeException(string paramName);
Constructs and initializes a new instance of the ArgumentOutOfRangeException class.
- paramName
- A String that contains the name of the parameter that caused the current exception. The content of paramName is intended to be understood by humans.
This constructor initializes the System.ArgumentOutOfRangeException.ParamName property of the new instance using paramName . The System.ArgumentOutOfRangeException.Message property is initialized to the system-supplied message provided by the constructor that takes no arguments.The System.ArgumentOutOfRangeException.ActualValue property is initialized to
null
.
System.ArgumentOutOfRangeException Class, System Namespace
public ArgumentOutOfRangeException(string paramName, string message);
Constructs and initializes a new instance of the ArgumentOutOfRangeException class.
- paramName
- A String that contains the name of the parameter that caused the current exception. The content of paramName is intended to be understood by humans.
- message
- A String that describes the error. The content of message 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 System.ArgumentOutOfRangeException.ParamName property of the new instance using paramName, and the System.ArgumentOutOfRangeException.Message property using message. If message isnull
, the System.ArgumentOutOfRangeException.Message property is initialized to the system-supplied message provided by the constructor that takes no arguments.The System.ArgumentOutOfRangeException.ActualValue property is initialized to
null
.
System.ArgumentOutOfRangeException Class, System Namespace
public ArgumentOutOfRangeException(string paramName, object actualValue, string message);
Constructs and initializes a new instance of the ArgumentOutOfRangeException class.
- paramName
- A String that contains the name of the parameter that caused the current exception. The content of paramName is intended to be understood by humans.
- actualValue
- The value of the argument that caused the current exception.
- message
- A String that describes the error. The content of message 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 System.ArgumentOutOfRangeException.ParamName property of the new instance using paramName, the System.ArgumentOutOfRangeException.ActualValue property using actualValue, and the System.ArgumentOutOfRangeException.Message property using message . If message isnull
, the System.ArgumentOutOfRangeException.Message property is initialized to the system-supplied message provided by the constructor that takes no arguments.[Note: The actualValue parameter contains the invalid argument that was passed to the method. Use the System.ArgumentOutOfRangeException.ParamName property to retrieve the name of the parameter used to pass actualValue.]
System.ArgumentOutOfRangeException Class, System Namespace
public virtual object ActualValue { get; }
Gets the value of the parameter that caused the current exception.
A Object that contains the value of the parameter that caused the current exception, ornull
if no value was specified to the constructor for the current instance.
This property is read-only.[Behaviors: The System.ArgumentOutOfRangeException.ActualValue property returns the same value as was passed into the constructor.]
[Overrides: Override the System.ArgumentOutOfRangeException.ActualValue property to customize the content or format of the value.]
[Usage: Use this property to retrieve the invalid argument.]
System.ArgumentOutOfRangeException Class, System Namespace
public override string Message { get; }
Gets the error message that explains the reason for the exception.
A String containing the error message. The error message should describe the expected values of the parameter that causes this exception.
This property is read-only.
System.ArgumentOutOfRangeException Class, System Namespace