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.