Skip to content

Gendarme.Rules.Exceptions.DoNotDestroyStackTraceRule(2.10)

Sebastien Pouliot edited this page Feb 9, 2011 · 3 revisions

DoNotDestroyStackTraceRule

Assembly: Gendarme.Rules.Exceptions
Version: 2.10

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.
Clone this wiki locally