System.ArgumentNullException Class

public class ArgumentNullException : ArgumentException

Base Types

Object
  Exception
    SystemException
      ArgumentException
        ArgumentNullException

Assembly

mscorlib

Library

BCL

Summary

Represents the error that occurs when an argument passed to a method is invalid because it is null .

Description

[Note: ArgumentNullException is thrown when a method is invoked and at least one of the passed arguments is null and should never be null .

ArgumentNullException behaves identically to ArgumentException. It is provided so that application code can differentiate between exceptions caused by null arguments and exceptions caused by non-null arguments. For errors caused by non-null arguments, see ArgumentOutOfRangeException .

]

Example

The following example demonstrates an error that causes the String class to throw a ArgumentNullException exception.

using System;
class ArgumentNullTest {
 public static void Main() {
 String[] s = null;
 String sep = " ";
 try {
 String j = String.Join(sep,s);
 }
 catch (ArgumentNullException e) {
 Console.WriteLine("Error: {0}",e);
 }
 }
}
   
The output is

Error: System.ArgumentNullException: Value cannot be null.

Parameter name: value

at System.String.Join(String separator, String[] value)

at ArgumentNullTest.Main()

See Also

System Namespace

Members

ArgumentNullException Constructors

ArgumentNullException() Constructor
ArgumentNullException(System.String) Constructor
ArgumentNullException(System.String, System.String) Constructor


ArgumentNullException() Constructor

public ArgumentNullException();

Summary

Constructs and initializes a new instance of the ArgumentNullException class.

Description

This constructor initializes the System.ArgumentNullException.Message property of the new instance to a system-supplied message that describes the error, such as "Argument cannot be null." This message takes into account the current system culture. The System.ArgumentNullException.ParamName property is initialized to null .

See Also

System.ArgumentNullException Class, System Namespace

ArgumentNullException(System.String) Constructor

public ArgumentNullException(string paramName);

Summary

Constructs and initializes a new instance of the ArgumentNullException class.

Parameters

paramName
A String that contains the name of the parameter that caused the exception. The content of paramName is intended to be understood by humans.

Description

This constructor initializes the System.ArgumentNullException.ParamName property of the new instance using paramName . The System.ArgumentNullException.Message property is initialized to the system-supplied message provided by the constructor that takes no arguments.

See Also

System.ArgumentNullException Class, System Namespace

ArgumentNullException(System.String, System.String) Constructor

public ArgumentNullException(string paramName, string message);

Summary

Constructs and initializes a new instance of the ArgumentNullException class.

Parameters

paramName
A String that contains the name of the parameter that caused the 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.ArgumentNullException.ParamName property of the new instance using paramName, and the System.ArgumentNullException.Message property using message. If message is null , the System.ArgumentNullException.Message property is initialized to the system-supplied message provided by the constructor that takes no arguments.

See Also

System.ArgumentNullException Class, System Namespace