Skip to main content

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 (_) {}
}