panicHandlerAsync<T> function

Future<T> panicHandlerAsync<T>(
  1. Future<T> fn(),
  2. FutureOr<T> handler(
    1. Panic panic
    )
)

Catches any Panic, Exception, or Error thrown by the function fn and handles.

Implementation

Future<T> panicHandlerAsync<T>(
    Future<T> Function() fn, FutureOr<T> Function(Panic panic) handler) async {
  try {
    return await fn();
  } on Panic catch (e) {
    return handler(e);
  } on Exception catch (e) {
    return handler(ExceptionPanic(e));
  } on Error catch (e) {
    return handler(ErrorPanic(e));
  }
}