| layout | page |
|---|---|
| title | CC0012 |
| tagline | RethrowExceptionAnalyzer |
|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.
{% highlight csharp %} try { } catch (System.Exception ex) { throw ex; } {% endhighlight %}
You will have two choices: you can rethrow the original exception as is:
{% highlight csharp %} try { } catch (System.Exception ex) { throw; } {% endhighlight %}
Or you can rethrow the original exception as an inner exception, like so:
{% highlight csharp %} try { } catch (System.Exception ex) { throw new Exception("some reason to rethrow", ex); } {% endhighlight %}

None
TBD