目錄
目錄

Avoid catches without on clauses.

This rule is available as of Dart 2.0.0.

Details

AVOID catches without on clauses.

Using catch clauses without on clauses make your code prone to encountering unexpected errors that won’t be thrown (and thus will go unnoticed).

BAD:

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

GOOD:

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

Usage

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

linter:
  rules:
    - avoid_catches_without_on_clauses