Flutter and Dart try catch—catch does not fire

Functions can throw anything, even things that aren’t an Exception:

void foo() {
  throw 42;
}

But the on Exception clause means that you are specifically catching only subclass of Exception.

As such, in the following code:

try {
  throw 42;
} on Exception catch (_) {
  print('never reached');
}

the on Exception will never be reached.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)