Dart Analyze logoDart Analyze/
DRT-W1692

Unused exception variable in catch clauseDRT-W1692

Major severityMajor
Bug Risk categoryBug Risk

The analyzer produces this diagnostic when a catch clause is found, and neither the exception parameter nor the optional stack trace parameter are used in the catch block.

Example

The following code produces this diagnostic because e isn't referenced:

void f() {
  try {
    int.parse(';');
  } on FormatException catch (e) {
    // ignored
  }
}

Common fixes

Remove the unused catch clause:

void f() {
  try {
    int.parse(';');
  } on FormatException {
    // ignored
  }
}