# Function: addOnError() (/jsdoc/pixi-vn/index/namespaces/Game/functions/addOnError)



\> **addOnError**(`value`): () => `void`

Defined in: [src/index.ts:363](https://github.com/DRincs-Productions/pixi-vn/blob/11c55b5d212c6c7eaffb12776b3f83f4d38e1ede/src/index.ts#L363)

Register an error handler. Multiple handlers can be registered; they
will be executed in registration order.

You can also check if the error is an instance of [PixiError](/jsdoc/pixi-vn/index/classes/PixiError) to handle specific errors related to Pixi’VN.

## Parameters [#parameters]

### value [#value]

[`OnErrorHandler`](/jsdoc/pixi-vn/index/type-aliases/OnErrorHandler)

## Returns [#returns]

() => `void`

## Example [#example]

```ts
// Register a synchronous error handler
Game.addOnError((error, props) => {
   props.notify("An error occurred")
   // send a notification to GlitchTip, Sentry, etc...
})

// Register an error handler for Pixi’VN specific errors
Game.addOnError((error, { notify }) => {
    if (error instanceof PixiError) {
        // ...
    }
});

// Register an asynchronous error handler
Game.addOnError(async (error, props) => {
   await logErrorToServer(error)
   props.notify("An error occurred")
})

// Register an error handler with step restoration/rollback
Game.addOnError(async (error, props) => {
   // Restore the game state to the previous step
   await stepHistory.back(props)
   props.notify("An error occurred, returning to previous step")
})
```
