C# logoC#/
CS-R1036

Widening of `Exception` in the catch clauseCS-R1036

Major severityMajor
Anti-pattern categoryAnti-pattern

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(/* */);
}
try
{
    // Some operation
}
catch (ArgumentException)
{
    // ...
    throw new SomeOtherException(/* */);
}

Reference