avoid_catching_errors

Group: style

Maturity: stable

Dart SDK: >= 2.0.0 • (Linter v0.1.31)

Since info is static, may be stale

View all Lint Rules

Using the Linter

DON'T explicitly catch Error or types that implement it.

Errors differ from Exceptions in that Errors can be analyzed and prevented prior to runtime. It should almost never be necessary to catch an error at runtime.

BAD:

try {
  somethingRisky();
} on Error catch(e) {
  doSomething(e);
}

GOOD:

try {
  somethingRisky();
} on Exception catch(e) {
  doSomething(e);
}

Usage

To enable the avoid_catching_errors lint, add avoid_catching_errors under linter > rules in your analysis_options.yaml file:

linter:
  rules:
    - avoid_catching_errors