selectCatchClause method

SCatchClause? selectCatchClause(
  1. STryStatement node,
  2. Object? thrownValue
)

The clause of node that handles thrownValue, or null when none does.

SCC31: an undefined name is a defect in the program text, not a runtime condition, so no clause may claim it — not on Object, not a bare catch (e). Real Dart rejects such a program at compile time, where no handler exists to run.

Implementation

SCatchClause? selectCatchClause(STryStatement node, Object? thrownValue) {
  if (thrownValue is UndefinedNameD4rtException) return null;
  // SCF4: a cancelled generator unwinds like a `return` — finally runs, no
  // catch clause may claim it.
  if (thrownValue is GeneratorCancelledSignal) return null;
  for (final clause in node.catchClauses) {
    if (catchClauseMatches(clause, thrownValue)) return clause;
  }
  return null;
}