System.ArgumentOutOfRangeException Class

public class ArgumentOutOfRangeException : ArgumentException

Base Types

Object
  Exception
    SystemException
      ArgumentException
        ArgumentOutOfRangeException

Assembly

mscorlib

Library

BCL

Summary

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.

Description

[Note: ArgumentOutOfRangeException is thrown when a method is invoked and at least one of the arguments passed to the method is not null 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 by null arguments. For errors caused by null arguments, see ArgumentNullException.

]

Example

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()

See Also

System Namespace

Members

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() Constructor

public ArgumentOutOfRangeException();

Summary

Constructs and initializes a new instance of the ArgumentOutOfRangeException class.

Description

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 .

See Also

System.ArgumentOutOfRangeException Class, System Namespace

ArgumentOutOfRangeException(System.String) Constructor

public ArgumentOutOfRangeException(string paramName);

Summary

Constructs and initializes a new instance of the ArgumentOutOfRangeException class.

Parameters

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.

Description

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 .

See Also

System.ArgumentOutOfRangeException Class, System Namespace

ArgumentOutOfRangeException(System.String, System.String) Constructor

public ArgumentOutOfRangeException(string paramName, string message);

Summary

Constructs and initializes a new instance of the ArgumentOutOfRangeException class.

Parameters

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.

Description

This constructor initializes the System.ArgumentOutOfRangeException.ParamName property of the new instance using paramName, and the System.ArgumentOutOfRangeException.Message property using message. If message is null , 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 .

See Also

System.ArgumentOutOfRangeException Class, System Namespace

ArgumentOutOfRangeException(System.String, System.Object, System.String) Constructor

public ArgumentOutOfRangeException(string paramName, object actualValue, string message);

Summary

Constructs and initializes a new instance of the ArgumentOutOfRangeException class.

Parameters

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.

Description

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 is null , 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.]

See Also

System.ArgumentOutOfRangeException Class, System Namespace

ArgumentOutOfRangeException.ActualValue Property

public virtual object ActualValue { get; }

Summary

Gets the value of the parameter that caused the current exception.

Property Value

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

Description

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

See Also

System.ArgumentOutOfRangeException Class, System Namespace