Skip to content

Safe

Functions

safe

luau
Safe.safe<T>(tryFn: () -> T, fallback: T | (err: unknown) -> T, equals: ((a: T, b: T) -> boolean)?): Graph.Node<T>

Creates a computed that evaluates tryFn and, if it throws, falls back to fallback, re-running and recovering automatically whenever its tracked dependencies change. fallback may be a static value or a recovery function receiving the caught error; a recovery function runs untracked so it cannot accidentally subscribe to extra dependencies. Pass equals to customize change detection (default ==).

Open Documentation

catch

luau
Safe.catch<T>(fn: () -> T, handler: (err: unknown) -> T): T

Synchronously runs fn and, if it throws, recovers with handler: a plain try/recover with no reactive node created. Both fn and handler run untracked, so reads inside them don't subscribe the surrounding computed or effect. If handler itself throws, that error propagates.

Open Documentation