Skip to main content

rethrow_outside_catch

A rethrow must be inside of a catch clause.

Description

#

The analyzer produces this diagnostic when a rethrow statement is outside a catch clause. The rethrow statement is used to throw a caught exception again, but there's no caught exception outside of a catch clause.

Example

#

The following code produces this diagnostic because therethrow statement is outside of a catch clause:

dart
void f() {
  rethrow;
}

Common fixes

#

If you're trying to rethrow an exception, then wrap the rethrow statement in a catch clause:

dart
void f() {
  try {
    // ...
  } catch (exception) {
    rethrow;
  }
}

If you're trying to throw a new exception, then replace the rethrow statement with a throw expression:

dart
void f() {
  throw UnsupportedError('Not yet implemented');
}