safeExecuteAsync<T> static method

Future<T?> safeExecuteAsync<T>(
  1. Future<T> function(), {
  2. ErrorCallback? onError,
  3. String? context,
})

Safely execute an async function with error handling.

Implementation

static Future<T?> safeExecuteAsync<T>(
  Future<T> Function() function, {
  ErrorCallback? onError,
  String? context,
}) async {
  try {
    return await function();
  } catch (error, stackTrace) {
    handleError(error, stackTrace, customHandler: onError, context: context);
    return null;
  }
}