[**Documentation**](../../../README)

***

[Documentation](../../../README) / [zerotal](../../README) / [helpers](../README) / rescueSync

# Function: rescueSync()

> **rescueSync**\<`T`\>(`callback`, `fallback`): `T`

Defined in: [packages/core/src/helpers/index.ts:224](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/core/src/helpers/index.ts#L224)

Synchronous sibling of `rescue` — for code paths that cannot await (JSON
parsing, attribute decoding, hot loops). Runs `callback` and returns its
value; on exception returns `fallback` (or the result of calling it with the
caught error).

## Type Parameters

### T

`T`

## Parameters

### callback

() => `T`

### fallback

`T` \| ((`error`) => `T`)

## Returns

`T`

## Example

```ts
const payload = rescueSync(() => JSON.parse(raw), {});
const cursor  = rescueSync(() => JSON.parse(atob(token)), null);
```
