empty_catches
Empty catch block.
Description
#The analyzer produces this diagnostic when the block in a catch
clause
is empty.
Example
#The following code produces this diagnostic because the catch block is empty:
dart
void f() {
try {
print('Hello');
} catch (exception) {}
}
Common fixes
#If the exception shouldn't be ignored, then add code to handle the exception:
dart
void f() {
try {
print('We can print.');
} catch (exception) {
print("We can't print.");
}
}
If the exception is intended to be ignored, then add a comment explaining why:
dart
void f() {
try {
print('We can print.');
} catch (exception) {
// Nothing to do.
}
}
If the exception is intended to be ignored and there isn't any good explanation for why, then rename the exception parameter:
dart
void f() {
try {
print('We can print.');
} catch (_) {}
}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。