tryError Documentation

Function: trySync()
Function

```ts function trySync<T>(fn, options?): TryResult<T, TryError<string>>; ``` Defined in: [sync.ts:65](https://github.com/oconnorjohnson/try-error/blob/e3ae0308069a4fba073f4543d527ad76373db795/src/sync.ts#L65) Wrap a synchronous operation that might throw Returns either the result or a TryError

tryError API Documentation v0.0.1-alpha.1


tryError API Documentation / trySync

Function: trySync()

function trySync<T>(fn, options?): TryResult<T, TryError<string>>;

Defined in: sync.ts:65

Wrap a synchronous operation that might throw Returns either the result or a TryError

Type Parameters

T

T

Parameters

fn

() => T

Function to execute

options?

TrySyncOptions

Optional configuration

Returns

TryResult<T, TryError<string>>

TryResult with success value or error

Example

const result = trySync(() => JSON.parse(jsonString));
if (isTryError(result)) {
  console.error("Parse failed:", result.message);
} else {
  console.log("Parsed:", result);
}