rethrow_outside_catch
rethrow 必須在 catch 子句內部。
描述
#當 rethrow 語句位於 catch 子句之外時,分析器會生成此診斷資訊。rethrow 語句用於再次丟擲捕獲到的異常,但在 catch 子句之外沒有捕獲到的異常。
示例
#以下程式碼會生成此診斷資訊,因為 rethrow 語句位於 catch 子句之外
dart
void f() {
rethrow;
}常見修正方法
#如果您試圖重新丟擲異常,請將 rethrow 語句包裝在 catch 子句中
dart
void f() {
try {
// ...
} catch (exception) {
rethrow;
}
}如果您試圖丟擲一個新異常,請將 rethrow 語句替換為 throw 表示式
dart
void f() {
throw UnsupportedError('Not yet implemented');
}