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:
void f() {
rethrow;
}
Common fixes
#
If you're trying to rethrow an exception, then wrap the
rethrow
statement
in a
catch
clause:
void f() {
try {
// ...
} catch (exception) {
rethrow;
}
}
If you're trying to throw a new exception, then replace the
rethrow
statement with a
throw
expression:
void f() {
throw UnsupportedError('Not yet implemented');
}
Unless stated otherwise, the documentation on this site reflects Dart 3.9.2. Page last updated on 2025-9-1. View source or report an issue.