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

Result<T, E> guardExceptionSync<T extends Object?, E extends Exception>(
  1. T block()
)

Executes a synchronous 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 function will throw Exception or its subtypes, but you want to let other errors (like Error) propagate uncaught.

Example:

final result = Result<int, FormatException>.guardExceptionSync(
  () => int.parse(input),
);

Implementation

static Result<T, E> guardExceptionSync<
  T extends Object?,
  E extends Exception
>(T Function() block) => Result<T, E>.guardSync(block);