A caught exception is thrown again with throw ex;, which loses its stack trace
What it finds
Inside catch (Exception ex), throw ex; throws the exception as if it started here: the stack trace that showed where it came from is replaced. throw; rethrows it with the trace intact; to add context, throw a new exception with ex as its inner exception.
From the rule's source, rethrow_loses_stack.rs.
using System; class Retry{ void Run() { try { Work(); } catch (InvalidOperationException ex) { Log(ex); throw ex;tx0 reports: throw ex; replaces the stack trace of the caught exception } catch (Exception ex) { throw new ApplicationException("failed", ex); } } void Work() { } void Log(Exception e) { }} Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/csharp:rethrow-loses-stack" = "off"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/csharp:rethrow-loses-stack] reason="..."tx0 explain tx0/csharp:rethrow-loses-stack shows the same in the terminal. Found a false positive? Report it.