In dart throw
is used no initiate an exception. Usually this is enough to just catch it and handle. However, there are cases when the
exceptions needs to be propagated further after being caught. This allows a handling of the exception on different levels. In such case it’s
recommended to use rethrow
instead of just throw
, to preserve the original stacktrace.
try {
...
} catch (ex) {
rethrow; // preserves the original exception with its stacktrace
}