C#

C#

Made by DeepSource

Do not throw from critical methods CS-W1008

Bug risk
Major

Certain methods such as ToString and Dispose are considered to be critical and are expected to work at all times. Throwing exceptions from such methods may interrupt the normal execution of your program. Consider returning an appropriate value instead.

Bad practice

public override string ToString()
{
    if (/* some condition */)
        throw new ArgumentException("Invalid `param`, could not generate `str`");
}

Recommended

public override string ToString()
{
    if (/* some condition */)
        return string.Empty;
}