The only difference I see is that onError also gets the Stacktrace passed as a parameter. In which situations would you choose one other the other?
The try / on / catch Blocks The on block is used when the exception type needs to be specified. The catch block is used when the handler needs the exception object. The try block must be followed by either exactly one on / catch block or one finally block (or one of both).
A future (lower case “f”) is an instance of the Future (capitalized “F”) class. A future represents the result of an asynchronous operation, and can have two states: uncompleted or completed. Note: Uncompleted is a Dart term referring to the state of a future before it has produced a value.
Future<T> onError<E extends Object>(FutureOr<T> Function(E, StackTrace) handleError, {bool Function(E)? test})
Future<T> catchError(Function onError, {bool Function(Object error)? test});
onError
is effectively a more precisely typed version of catchError
.
So, with onError
you can catch specific error types and specify a correctly typed error handler function, rather than all types and just a Function with catchError
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With