tryCatch<T> function

T? tryCatch<T>(
  1. T worker(), [
  2. T? onError(
    1. dynamic e
    )?
])

Implementation

T? tryCatch<T>(T Function() worker, [T? Function(dynamic e)? onError]) {
  try {
    return worker();
  } catch (e) {
    return onError?.call(e);
  }
}