wrapError method

Object? wrapError(
  1. Object error,
  2. StackTrace stackTrace
)

If any error is thrown by reduce or before, you have the chance to further process it by using wrapError. Usually this is used to wrap the error inside of another that better describes the failed action. For example, if some action converts a String into a number, then instead of throwing a FormatException you could do:

wrapError(error, _) => UserException("Please enter a valid number.", cause: error)

If you want to disable the error you can return null. For example, if you want to disable errors of type MyException:

wrapError(error, _) => (error is MyException) ? null : error

If you don't want to modify the error, just return it unaltered (or don't override this method).

See also:

  • GlobalWrapError which is a global error wrapper that will be called after this one.

Implementation

Object? wrapError(Object error, StackTrace stackTrace) => error;