safeUpdateWithHandler<T> static method

T safeUpdateWithHandler<T>(
  1. T update(),
  2. T onError(
    1. Object error,
    2. StackTrace stackTrace
    )
)

Execute a function with custom error handler

Implementation

static T safeUpdateWithHandler<T>(
  T Function() update,
  T Function(Object error, StackTrace stackTrace) onError,
) {
  try {
    return update();
  } catch (e, stackTrace) {
    Logger.error('State update error (custom handler)', e);
    Logger.debug('Stack trace', stackTrace);
    return onError(e, stackTrace);
  }
}