Wraps a function that may throw an exception in a Result.
This is a fundamental utility for converting traditional exception-based
error handling into Result-based error handling. Any thrown value is
converted to an Error object for consistent error handling.
If the function executes successfully, returns Result.Ok with the result.
If the function throws, returns Result.Err with the caught error.
Wraps a function that may throw an exception in a
Result
.This is a fundamental utility for converting traditional exception-based error handling into Result-based error handling. Any thrown value is converted to an Error object for consistent error handling.
If the function executes successfully, returns
Result.Ok
with the result. If the function throws, returnsResult.Err
with the caught error.