MCPcopy Create free account
hub / github.com/Effect-TS/effect / try_

Function try_

packages/effect/src/internal/effect.ts:1028–1045  ·  view source on GitHub ↗
(
  options: {
    readonly try: LazyArg<A>
    readonly catch: (error: unknown) => E
  } | LazyArg<A>
)

Source from the content-addressed store, hash-verified

1026
1027/** @internal */
1028const try_ = <A, E = Cause.UnknownError>(
1029 options: {
1030 readonly try: LazyArg<A>
1031 readonly catch: (error: unknown) => E
1032 } | LazyArg<A>
1033): Effect.Effect<A, E> => {
1034 const evaluate = typeof options === "function" ? options : options.try
1035 const catcher = typeof options === "function"
1036 ? ((cause: unknown) => new UnknownError(cause, "An error occurred in Effect.try"))
1037 : options.catch
1038 return suspend(() => {
1039 try {
1040 return succeed(internalCall(evaluate))
1041 } catch (err) {
1042 return fail(internalCall(() => catcher(err)) as E)
1043 }
1044 })
1045}
1046/** @internal */
1047export { try_ as try }
1048

Callers

nothing calls this directly

Calls 3

succeedFunction · 0.70
failFunction · 0.70
suspendFunction · 0.50

Tested by

no test coverage detected