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');
}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。