C#

C#

Made by DeepSource

Widening of Exception in the catch clause CS-R1036

Anti-pattern
Major

Exception handling is all about error handling and recovery which can vary depending on the exception that is being caught. In this case, while the exception that is being caught is specific, the catch clause contains one or more throw statements where the exception that is being thrown is generic, i.e. the exception is generalized. It is recommended that you refactor this and throw a specific exception instead.

Bad Practice

try
{
    // Some operation
}
catch (ArgumentException)
{
    // ...
    throw new Exception(/* */);
}

Recommended

try
{
    // Some operation
}
catch (ArgumentException)
{
    // ...
    throw new SomeOtherException(/* */);
}

Reference