| 1191 | |
| 1192 | /** @internal */ |
| 1193 | const 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 */ |
| 1212 | export { try_ as try } |
| 1213 | |