empty-catches
Same as empty_catches in Dart lints
- Group
- Suspicious
- Path
lint/suspicious/empty-catches- Default
- On (recommended)
- Origin
- Dart lints
- Rule
- 229 of 512
Flags empty catch blocks.
A catch clause with no body silently swallows the exception, hiding failures
that should be handled, logged, or rethrown and making bugs far harder to
diagnose. Handle the error, or at minimum log it, rather than discarding it.
Two escape hatches match the official lint: a catch whose body contains a
comment (the emptiness is deliberate and documented), and a catch that binds
its exception to _, an explicit "I am ignoring this" marker.
This includes catch clauses inside anonymous functions.
Invalid
void f1() {
try {
doThing();
} catch (e) {}
}
void f2() {
try {
doThing();
} on Exception catch (e) {}
}
void f3() {
try {
doThing();
} catch (e, st) {}
}
void f4() {
try {
doThing();
} on StateError {}
}
void f5() {
try {
doThing();
} catch (error) {}
}
void f6() {
try {
doThing();
} catch (e) {
}
} doThing(); } catch (e) {} doThing(); } on Exception catch (e) {} doThing(); } catch (e, st) {} doThing(); } on StateError {} doThing(); } catch (error) {} } catch (e) { }Valid
void g1() {
try {
doThing();
} catch (e) {
print(e);
}
}
void g2() {
try {
doThing();
} catch (_) {}
}
void g3() {
try {
doThing();
} catch (e) {
// Failure is expected and intentionally ignored here.
}
}
void g4() {
try {
doThing();
} on Exception catch (e) {
handle(e);
}
}
void g5() {
try {
doThing();
} on StateError catch (_) {}
}
void g6() {
try {
doThing();
} catch (e, st) {
print('$e $st');
}
}
String documentedInterpolation() => '${(() {
try {
doThing();
} catch (error) { /* Deliberately ignore this } and { failure. */ }
return '';
})()}';Configure empty-catches
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"suspicious": {
"empty-catches": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/suspicious/empty-catches: <reason>More suspicious rules
- empty-statements
empty_statementsrecommendedFlags stray empty statements (a lone
;). - no-duplicate-case-values
no_duplicate_case_valuesrecommendedFlags semantically equal constant values within one switch.
- no-empty-block
no-empty-blockFlags empty blocks (
{}). - no-equal-arguments
no-equal-argumentsFlags an argument passed more than once in the same invocation.
- no-equal-then-else
no-equal-then-elserecommendedFlags an
if/elseor ternary whose two branches are identical. - no-magic-string
Extract inline string literals into named variables or constants.
- no-self-comparisons
no_self_comparisonsrecommendedFlags proven self-comparisons of side-effect-free scalar values.
- no-wildcard-variable-uses
no_wildcard_variable_usesrecommendedFlags references to a wildcard variable or parameter (a name made solely of underscores, such as
_or__).