runCatching<T> function

T? runCatching<T>(
  1. T runnable(), [
  2. T? onFailure(
    1. CatchException e
    )?
])

运行,内置捕获函数,有返回

Implementation

T? runCatching<T>(T Function() runnable, [T? Function(CatchException e)? onFailure]) {
  try {
    return runnable.call();
  } on Error catch (e) {
    return onFailure?.call(CatchException(e, null));
  } on Exception catch (e) {
    return onFailure?.call(CatchException(null, e));
  }
}