Skip to content

Latest commit

 

History

History
30 lines (21 loc) · 850 Bytes

File metadata and controls

30 lines (21 loc) · 850 Bytes

Pattern: Missing use of ArgumentException

Issue: -

Description

Argument checks have a substantial impact on code size and often dominate the code for small functions and property setters. These checks prevent inlining and cause substantial instruction-cache pollution. Throw-helper methods such as ArgumentException.ThrowIfNullOrEmpty(String, String) are simpler and more efficient than if blocks that construct a new exception instance.

Example of incorrect code:

void TestMethod(string arg)
{
    if (string.IsNullOrEmpty(arg))
        throw new ArgumentException("", "arg");
}

Example of correct code:

void TestMethod(string arg)
{
    ArgumentException.ThrowIfNullOrEmpty(arg);
}

Further Reading