tryCatch<T> static method
Execute function with try-catch and optional error callback
Example:
final result = FSErrors.tryCatch(
() => riskyOperation(),
onError: (e, stack) => print('Error: $e'),
fallback: 'default',
);
Implementation
static T? tryCatch<T>(
T Function() action, {
Function(dynamic error, StackTrace stack)? onError,
T? fallback,
}) {
try {
return action();
} catch (error, stack) {
onError?.call(error, stack);
return fallback;
}
}