| Property | Value |
|---|---|
| Package | Philips.CodeAnalysis.MaintainabilityAnalyzers |
| Diagnostic ID | PH2121 |
| Category | Documentation |
| Analyzer | DocumentThrownExceptionsAnalyzer |
| CodeFix | Yes |
| Severity | Error |
| Enabled By Default | Yes |
Exceptions that do not include a Message are not helpful for debugging the issue at hand.
The analyzer ignores any NotImplementedException from this rule.
When throwing exceptions, use a constructor overload that accepts a Message.
Code that triggers a diagnostic:
public class BadExample {
public void BadCode() {
throw new ArgumentException();
}
}And the replacement code:
public class GoodExample {
public void GoodCode() {
throw new ArgumentException("Helpful message for debugging");
}
}This analyzer does not offer any special configuration. The general ways of suppressing diagnostics apply.
See these analyzers for other rules related to exceptions:
| ID | Title |
|---|---|
| PH2120 | Document thrown exceptions |
| PH2121 | Throw informational exceptions |
| PH2122 | Avoid Exceptions from unexpected locations |
| PH2124 | Document unhandled exceptions |