avoid-nested-try-statements

Path
lint/complexity/avoid-nested-try-statements
Default
Off, opt in
Origin
Falcon
Rule
104 of 512

Reports deeply nested try statements.

max-nesting (integer, default: 2) limits nesting of this construct. Local functions and closures restart the nesting count.

Invalid

example.dartdart
void handle() {
  try {
    try { print(1); } catch (_) {}
  } catch (_) {}
}
Nesting exceeds 1 levels. Extract the nested construct into a helper.
2 try {
3 try { print(1); } catch (_) {}

Valid

example.dartdart
void handle() {
  try { print(1); } catch (_) {}
  try { void local() { try { print(2); } catch (_) {} } local(); } catch (_) {}
}

Configure avoid-nested-try-statements

Set its severity in falcon.json. See the configuration guide.

falcon.jsonjson
{
  "linter": {
    "rules": {
      "complexity": {
        "avoid-nested-try-statements": "error"
      }
    }
  }
}

Or silence one occurrence with a suppression comment; the reason is required.

example.dartdart
// falcon-ignore lint/complexity/avoid-nested-try-statements: <reason>