panicHandler<T> function

T panicHandler<T>(
  1. T fn(),
  2. T handler(
    1. Panic panic
    )
)

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

Implementation

T panicHandler<T>(T Function() fn, T Function(Panic panic) handler) {
  try {
    return fn();
  } on Panic catch (e) {
    return handler(e);
  } on Exception catch (e) {
    return handler(ExceptionPanic(e));
  } on Error catch (e) {
    return handler(ErrorPanic(e));
  }
}