use_rethrow_when_possible

Group: style

Maturity: stable

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

pedantic

View the Project on GitHub dart-lang/linter

DO use rethrow to rethrow a caught exception.

As Dart provides rethrow as a feature, it should be used to improve terseness and readability.

BAD:

try {
  somethingRisky();
} catch(e) {
  if (!canHandle(e)) throw e;
  handle(e);
}

GOOD:

try {
  somethingRisky();
} catch(e) {
  if (!canHandle(e)) rethrow;
  handle(e);
}