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 (_) {}
}
Was this page's content helpful?
Thank you for your feedback!
Provide details Thank you for your feedback! Please let us know what we can do to improve.
Provide details Unless stated otherwise, the documentation on this site reflects Dart 3.8.1. Page last updated on 2025-05-08. View source or report an issue.