Skip to content

Gendarme.Rules.BadPractice.CheckNewExceptionWithoutThrowingRule(git)

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

CheckNewExceptionWithoutThrowingRule

Assembly: Gendarme.Rules.BadPractice
Version: git

Description

This rule checks for exception objects which are created but not thrown, not returned, and not passed to another method as an argument.

Examples

Bad example:

void MissingThrow (object arg)
{
    if (arg == null) {
        new ArgumentNullException ("arg");
    }
    DoWork (arg);
}

Good examples:

void Throw (object arg)
{
    if (arg == null) {
        throw new ArgumentNullException ("arg");
    }
    DoWork (arg);
}
Exception CreateException ()
{
    return new Exception ();
}

Source code

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

Clone this wiki locally