(
evaluate: LazyArg<A> | {
readonly try: LazyArg<A>
readonly catch: (error: unknown) => E
}
)
| 470 | } |
| 471 | |
| 472 | export { |
| 473 | /** |
| 474 | * Wraps a synchronous computation that may throw into a `Result` safely. |
| 475 | * |
| 476 | * **Details** |
| 477 | * |
| 478 | * - If the function returns normally, the result is `Success<A>` |
| 479 | * - If the function throws, the exception is caught and becomes `Failure<E>` |
| 480 | * - With a single function argument, the error type is `unknown` |
| 481 | * - With `{ try, catch }` options, the `catch` function maps the thrown value to `E` |
| 482 | * |
| 483 | * **Example** (Catching JSON parse errors) |
| 484 | * |
| 485 | * ```ts import.meta.vitest |
| 486 | * import { Result } from "effect" |
| 487 | * |
| 488 | * Result.try(() => JSON.parse('{"name": "Alice"}')) // => Result.succeed({ name: "Alice" }) |
| 489 | * |
| 490 | * const err = Result.try({ |
| 491 | * try: () => JSON.parse("not json"), |
| 492 | * catch: (e) => `Parse failed: ${e}` |
| 493 | * }) |
| 494 | * Result.isFailure(err) // => true |
nothing calls this directly
no test coverage detected
searching dependent graphs…