[**@bondsports/general**](../README.md) • **Docs**

***

[@bondsports/general](../globals.md) / tryCatch

# Function: tryCatch()

> **tryCatch**\<`T`\>(`fn`, `onError`?, `onFinally`?): `T`

Wraps a synchronise function in a try-catch-finally block and calls the onError and onFinally respectably.

## Type Parameters

• **T**

The return type of the synchronised function

## Parameters

• **fn**

{() => T} - The function to execute

• **onError?**

{(error: Error) => void} - (Optional) The function to call if an error is thrown.

• **onFinally?**

{() => void} - (Optional) The function to call after the try-catch block

## Returns

`T`

## Defined in

[utils/general.util.ts:172](https://github.com/Bond-Sports/bondUtils/blob/545f16ceb055481acfd7641d7809c0f252d3a5e6/packages/general/src/utils/general.util.ts#L172)
