Moeru AI Std
Utils

Try Catch

Convert throwing functions into data/error objects.

tryCatch

import {  } from '@moeru/std/try-catch'

const  = (: string) => .()

const { ,  } = (() => ('{"hello":"world"}'))

if ()
  .('Failed to parse JSON', )
else
  .(.hello)

tryCatchAsync

import {  } from '@moeru/std/try-catch'

const  = async (: string) => {
  const  = await ()
  if (!.)
    throw new (.)
  return .()
}

const { ,  } = await (() => ('https://example.com/data.json'))

if ()
  .('Request failed', )
else
  .()

Remarks

This wrapper keeps your call sites non-throwing and therefore easier to compose. It is a lightweight alternative to result libraries—if you need richer ergonomics (matching, chaining, etc.) consider adopting a full Result/Try monad.