# 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/998c1a75c5978f24c0dc137af5f42b90b2803967/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]

```typescript
// 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")
})
```
