Skip to content

Latest commit

 

History

History
56 lines (42 loc) · 1.68 KB

File metadata and controls

56 lines (42 loc) · 1.68 KB

PH2121: Throw informational exceptions

Property Value
Package Philips.CodeAnalysis.MaintainabilityAnalyzers
Diagnostic ID PH2121
Category Documentation
Analyzer DocumentThrownExceptionsAnalyzer
CodeFix Yes
Severity Error
Enabled By Default Yes

Introduction

Exceptions that do not include a Message are not helpful for debugging the issue at hand.

The analyzer ignores any NotImplementedException from this rule.

How to solve

When throwing exceptions, use a constructor overload that accepts a Message.

Example

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");
  }
}

Configuration

This analyzer does not offer any special configuration. The general ways of suppressing diagnostics apply.

Similar Analyzers

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