Skip to main content

prefer-correct-throws

added in: 1.19.0
Pro+

Warns when a declaration is missing or has an unnecessary @Throws() annotation.

info

To use the @Throws() annotation, install the dart-code-metrics-annotations package.

And to get warnings for unhandled exceptions thrown by invocations with the @Throws() annotation, enable the handle-throwing-invocations rule.

Example

() // LINT
void fn() {
print('hi');
}

// LINT
void withThrow() {
throw Error();
}

// LINT
void withRethrow() {
try {
...
} catch (_) {
rethrow;
}
}

✅ Good:

void fn() {
print('hi');
}

()
void withThrow() {
throw Error();
}

()
void withRethrow() {
try {
...
} catch (_) {
rethrow;
}
}