safeExecute<T> static method

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

Safely execute a function with error handling.

Implementation

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