executeGuarded<T> function
Future<T>
executeGuarded<T>({
- required Future<
T> function(), - required Future<
T> onError(- Object error,
- StackTrace stackTrace
A convenience method to execute a function and handle any errors via onError
callback.
Implementation
Future<T> executeGuarded<T>({
required Future<T> Function() function,
required Future<T> Function(Object error, StackTrace stackTrace) onError,
}) async {
try {
return await function();
} catch (error, stackTrace) {
return onError(error, stackTrace);
}
}