RecoverExt<Input, Output> extension
Adds the recover method to the ParameterizedResultInteractor class.
This method allows you to recover from an exception thrown by the interactor's getOrThrow method.
The callback will be called with the exception that was thrown.
The result of the callback will be returned instead of the exception.
Example:
final interactor = MyInteractor();
await interactor
.recover((exception) => 'Recovered from: $exception')
.run(input);
You can also specify the type of exception you want to recover from:
final interactor = MyInteractor();
await interactor
.typedRecover<FormatException>((exception) => 'Recovered from: $exception')
.run(input);
It is also possible to recover from exceptions based on a predicate:
final interactor = MyInteractor();
await interactor
.checkedRecover(
(exception) => 'Recovered from: $exception',
(exception) => exception is FormatException,
).run(input);
- on
-
- ParameterizedResultInteractor<
Input, Output>
- ParameterizedResultInteractor<
Methods
-
checkedRecover(
FutureOr< Output> callback(Exception), FutureOr<bool> predicate(Exception)) → ParameterizedResultInteractor<Input, Output> -
Available on ParameterizedResultInteractor<
This method allows you to recover from an exception thrown by the interactor's getOrThrow method. Only exceptions that which theInput, Output> , provided by the RecoverExt extensionpredicatereturnstruewill be recovered from. -
recover(
FutureOr< Output> callback(Exception)) → ParameterizedResultInteractor<Input, Output> -
Available on ParameterizedResultInteractor<
This method allows you to recover from any Exception thrown by the interactor's getOrThrow method.Input, Output> , provided by the RecoverExt extension -
typedRecover<
ExceptionType extends Exception> (FutureOr< Output> callback(ExceptionType)) → ParameterizedResultInteractor<Input, Output> -
Available on ParameterizedResultInteractor<
This method allows you to recover from an Exception of a specific type thrown by the interactor's getOrThrow method.Input, Output> , provided by the RecoverExt extension