Skip to content

Gendarme.Rules.Exceptions.AvoidArgumentExceptionDefaultConstructorRule(git)

Sebastien Pouliot edited this page Mar 2, 2011 · 1 revision

AvoidArgumentExceptionDefaultConstructorRule

Assembly: Gendarme.Rules.Exceptions
Version: git

Description

This rule checks that every System.ArgumentException, System.ArgumentNullException, System.ArgumentOutOfRangeException, or System.DuplicateWaitObjectException exception created is provided with some useful information about the exception being thrown, minimally the parameter name.

Examples

Bad example:

public void Add (object key, object value)
{
    if ((obj == null) || (key == null)) {
        throw new ArgumentNullException ();
    }
    Inner.Add (key, value);
}

Good example:

public void Add (object key, object value)
{
    if (key == null) {
        throw new ArgumentNullException ("key");
    }
    if (obj == value) {
        throw new ArgumentNullException ("value");
    }
    Inner.Add (key, value);
}

Notes

  • This rule is available since Gendarme 2.0

Source code

You can browse the latest source code of this rule on github.com

Clone this wiki locally