dead_ code_ catch_ following_ catch
Details about the 'dead_code_catch_following_catch' diagnostic produced by the Dart analyzer.
Dead code: Catch clauses after a 'catch (e)' or an 'on Object catch (e)' are never reached.
Description
#
The analyzer produces this diagnostic when a
catch clause is found that can't be executed
because it's after a catch clause of the form
catch (e) or on Object catch (e).
The first catch clause that matches the thrown
object is selected, and both of those forms will match any
object, so no catch clauses that follow them will
be selected.
Example
#The following code produces this diagnostic:
void f() {
try {
// ...
} catch (e) {
// Not reached.
} on String {
// ...
}
}
Common fixes
#If the clause should be selectable, then move the clause before the general clause:
void f() {
try {
// ...
} on String {
// ...
} catch (e) {
// ...
}
}
If the clause doesn't need to be selectable, then remove it:
void f() {
try {
// ...
} catch (e) {
// ...
}
}
除非另有说明,文档之所提及适用于 Dart 3.12.2 版本报告页面问题.