TypeName | RethrowExceptionAnalyzer |
Check Id | CC0012 |
Category | Naming |
Severity | Warning |
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.
try { }
catch (System.Exception ex)
{
throw ex;
}
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);
}
None
TBD