Skip to main content

avoid-only-rethrow

added in: 1.18.0
Pro+

Warns when a catch clause has only a rethrow expression.

Example

❌ Bad:

void main() {
try {
...
} on Object catch (error) {
rethrow; // LINT
}
}

✅ Good:

void main() {
try {
...
} on Object catch (error) {
if (error is Exception) {
// handle
return;
}

rethrow;
}
}