marinasundstrom / CheckedExceptions

Enforce better exception handling in C#/.NET by ensuring exceptions are explicitly handled.
MIT License
4 stars 0 forks source link

Add ability to configure analyzer #42

Closed marinasundstrom closed 1 day ago

marinasundstrom commented 5 days ago

Sometimes you want the analyzer to ignore certain exceptions per project basis. You also might want softer warnings about exceptions that might but are are unlikely to occur - especially if you are a library author.

Add configuration via a file such as this: CheckedExceptions.config.json:

{
  "ignoredExceptions": [
    "System.ArgumentNullException",
    "System.NotImplementedException"
  ],
  "informationalExceptions": [
    "System.IO.IOException",
    "System.TimeoutException"
  ]
}

Ignored exceptions

Ignored exceptions will be ignored and not reported on.

Information exceptions

Informational exceptions will report separately but not be enforced to be checked by the analyzer:

private static readonly DiagnosticDescriptor RuleIgnoredException = new DiagnosticDescriptor(
    "THROW002",
    "Ignored exception may cause runtime issues",
    "Exception '{0}' is ignored by configuration but may cause runtime issues if unhandled",
    "Usage",
    DiagnosticSeverity.Info,
    isEnabledByDefault: true);

This will make it possible to distinguish categories of exceptions. So that if you want to enforce THROW001 as error, you can still have soft warnings for certain exceptions.