Skip to content

Gendarme.Rules.Exceptions.DoNotDestroyStackTraceRule(git)

Sebastien Pouliot edited this page Mar 2, 2011 · 1 revision

DoNotDestroyStackTraceRule

Assembly: Gendarme.Rules.Exceptions
Version: git

Description

This rule will fire if a catch handler throws the exception it caught. What it should do instead is rethrow the original exception (e.g. use throw instead of throw ex ). This is helpful because rethrow preserves the stacktrace of the original exception.

Examples

Bad example:

try {
    Int32.Parse ("Broken!");
}
catch (Exception ex) {
    Assert.IsNotNull (ex);
    throw ex;
}

Good example:

try {
    Int32.Parse ("Broken!");
}
catch (Exception ex) {
    Assert.IsNotNull (ex);
    throw;
}

Notes

  • Prior to Gendarme 2.0 this rule was named DontDestroyStackTraceRule.

Source code

You can browse the latest source code of this rule on github.com

Clone this wiki locally