guardExceptionAsync<T extends Object?, E extends Exception> static method

Future<Result<T, E>> guardExceptionAsync<T extends Object?, E extends Exception>(
  1. Future<T> asyncBlock()
)

Executes an asynchronous function, catching only Exception types.

A convenience method that constrains the error type to Exception rather than accepting any Object. Use this when you know the async function will throw Exception or its subtypes, but you want to let other errors (like Error) propagate uncaught.

Example:

final result = await Result<String, IOException>.guardExceptionAsync(
  () => file.readAsString(),
);

Implementation

static Future<Result<T, E>> guardExceptionAsync<
  T extends Object?,
  E extends Exception
>(Future<T> Function() asyncBlock) => guardAsync<T, E>(asyncBlock);