rethrow_ outside_ catch
Details about the 'rethrow_outside_catch' diagnostic produced by the Dart analyzer.
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 the
rethrow 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');
}
除非另有说明,文档之所提及适用于 Dart 3.12.2 版本报告页面问题.