Skip to main content

avoid-identical-exception-handling-blocks

added in: 1.9.0

Warns when a try / catch has multiple catch blocks with the same body.

Consider adding additional information for each caught exception.

Example

❌ Bad:

void main() {
try {
print('hello');
} on StateError catch (error) {
print(error);
} on Exception catch (error) { // LINT
print(error);
}
}

✅ Good:

void main() {
try {
print('hello');
} on StateError catch (error) {
print('Got StateError $error');
} on Exception catch (error) {
print('Got Exception $error');
}
}