A public exception class lacks one of the usual constructors: none, a message, or a message and an inner exception
What it finds
Code that wraps or rethrows exceptions expects every exception type to offer a parameterless constructor, one taking a message, and one taking a message and an inner exception. A type without them forces callers to drop the message or the cause. The rule reports public classes deriving from a type named ...Exception that declare constructors but not all three; classes with a primary constructor are left alone.
From the rule's source, exception_without_standard_constructors.rs.
using System; public class ParseException : Exceptiontx0 reports: ParseException has no constructor (), (string, Exception){ public ParseException(string message) : base(message) { }} public class FullException : Exception{ public FullException() { } public FullException(string message) : base(message) { } public FullException(string message, Exception inner) : base(message, inner) { }} Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/csharp:exception-without-standard-constructors" = "warning"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:exception-without-standard-constructors] reason="..."tx0 explain tx0/csharp:exception-without-standard-constructors shows the same in the terminal. Found a false positive? Report it.