| 1026 | |
| 1027 | /** @internal */ |
| 1028 | const 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 */ |
| 1047 | export { try_ as try } |
| 1048 | |