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

Function try_

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

Source from the content-addressed store, hash-verified

1191
1192/** @internal */
1193const try_ = <A, E = Cause.UnknownError>(
1194 options: {
1195 readonly try: LazyArg<A>
1196 readonly catch: (error: unknown) => E
1197 } | LazyArg<A>
1198): Effect.Effect<A, E> => {
1199 const evaluate = typeof options === "function" ? options : options.try
1200 const catcher = typeof options === "function"
1201 ? ((cause: unknown) => new UnknownError(cause, "An error occurred in Effect.try"))
1202 : options.catch
1203 return suspend(() => {
1204 try {
1205 return succeed(evaluate())
1206 } catch (err) {
1207 return fail(catcher(err) as E)
1208 }
1209 })
1210}
1211/** @internal */
1212export { try_ as try }
1213

Callers

nothing calls this directly

Calls 4

evaluateFunction · 0.90
succeedFunction · 0.70
failFunction · 0.70
suspendFunction · 0.50

Tested by

no test coverage detected