use_rethrow_when_possible

Group: style

Maturity: stable

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

Since info is static, may be stale
pedanticeffective dart

View all Lint Rules

Using the 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);
}