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:
void f() {
try {
print('Hello');
} catch (exception) {}
}
Common fixes
#If the exception shouldn't be ignored, then add code to handle the exception:
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:
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:
void f() {
try {
print('We can print.');
} catch (_) {}
}
Unless stated otherwise, the documentation on this site reflects Dart 3.7.3. Page last updated on 2025-05-08. View source or report an issue.