Fork me on GitHub
TypeName RethrowExceptionAnalyzer
Check Id CC0012
Category Naming
Severity Warning

Cause

Throwing the same exception as passed to the ‘catch’ block lose the original stack trace and will make debugging this exception a lot more difficult.
The correct way to rethrow an exception without changing it is by using ‘throw’ without any parameter.

Example

try { }
catch (System.Exception ex)
{
    throw ex;
}

Code fix

You will have two choices: you can rethrow the original exception as is:

try { }
catch (System.Exception ex)
{
    throw;
}

Or you can rethrow the original exception as an inner exception, like so:

try { }
catch (System.Exception ex)
{
    throw new Exception("some reason to rethrow", ex);
}

Code fix

Related rules

None

See also

TBD