MCPcopy Create free account
hub / github.com/effect-app/libs / try_

Function try_

repos/effect/packages/effect/src/Result.ts:472–491  ·  view source on GitHub ↗
(
  evaluate: LazyArg<A> | {
    readonly try: LazyArg<A>
    readonly catch: (error: unknown) => E
  }
)

Source from the content-addressed store, hash-verified

470}
471
472export {
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

Callers

nothing calls this directly

Calls 5

isFunctionFunction · 0.90
catchMethod · 0.80
succeedFunction · 0.70
evaluateFunction · 0.70
failFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…