catching<I, O> function

Mapping<I, O?> catching<I, O>(
  1. O execute(
    1. I input
    ), {
  2. String? debugLabel,
  3. Logger? logger,
})

Implementation

Mapping<I, O?> catching<I, O>(O execute(I input),
    {String? debugLabel, Logger? logger}) {
  return (I input) {
    try {
      final result = execute(input);
      if (result is Future) {
        result.catchError((e, StackTrace stack) {
          (logger ?? _log)
              .severe((debugLabel ?? "Error catching") + ": $e", e, stack);
        });
      }
      return result;
    } catch (e, stack) {
      (logger ?? _log)
          .severe((debugLabel ?? "Error catching") + ": $e", e, stack);
      return null;
    }
  };
}