public class ArgumentNullException : ArgumentException
Object
Exception
SystemException
ArgumentException
ArgumentNullException
mscorlib
BCL
Represents the error that occurs when an argument passed to a method is invalid because it isnull
.
[Note: ArgumentNullException is thrown when a method is invoked and at least one of the passed arguments isnull
and should never benull
.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 .]
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()
System Namespace
ArgumentNullException Constructors
ArgumentNullException() Constructor
ArgumentNullException(System.String) Constructor
ArgumentNullException(System.String, System.String) Constructor
public ArgumentNullException();
Constructs and initializes a new instance of the ArgumentNullException class.
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 tonull
.
System.ArgumentNullException Class, System Namespace
public ArgumentNullException(string paramName);
Constructs and initializes a new instance of the ArgumentNullException class.
- 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.
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.
System.ArgumentNullException Class, System Namespace
public ArgumentNullException(string paramName, string message);
Constructs and initializes a new instance of the ArgumentNullException class.
- 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.
This constructor initializes the System.ArgumentNullException.ParamName property of the new instance using paramName, and the System.ArgumentNullException.Message property using message. If message isnull
, the System.ArgumentNullException.Message property is initialized to the system-supplied message provided by the constructor that takes no arguments.
System.ArgumentNullException Class, System Namespace