Skip to content

Gendarme.Rules.Exceptions.DoNotThrowReservedExceptionRule(2.10)

Sebastien Pouliot edited this page Feb 9, 2011 · 3 revisions

DoNotThrowReservedExceptionRule

Assembly: Gendarme.Rules.Exceptions
Version: 2.10

Description

This rule will fire if an System.ExecutionEngineException, System.IndexOutOfRangeException, NullReferenceException, or System.OutOfMemoryException class is instantiated. These exceptions are for use by the runtime and should not be thrown by user code.

Examples

Bad example:

public void Add (object obj)
{
    if (obj == null) {
        throw new NullReferenceException ("obj");
    }
    Inner.Add (obj);
}

Good example:

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

Notes

  • This rule is available since Gendarme 2.0
Clone this wiki locally