Catch multiple specific exception types in Dart with one catch expression

You can only specify one type per on xxx catch(e) { line or alternatively use
catch(e) to catch all (remaining – see below) exception types.
The type after on is used as type for the parameter to catch(e). Having a set of types for this parameter wouldn’t work out well.

try {
  ...
} on A catch(e) {
  ...
} on B catch(e) {
  ...
} catch(e) { // everything else
}

Leave a Comment