> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# XErrorCallback

> XErrorCallback

# XErrorCallback

A callback that is called if an error occurs in the gaming OS or gaming runtime.

## Syntax

```cpp theme={null}
bool XErrorCallback(  
         HRESULT hr,  
         const char* msg,  
         void* context  
)  
```

### Parameters

*hr*   \_In\_\
Type: HRESULT

The HRESULT code associated with the error.

*msg*   \_In\_z\_\
Type: char\*

Text description of the error.

*context*   \_In\_\
Type: void\*

Context pointer for the callback.

### Return value

Type: bool

Return `true` to indicate that the system should continue on and do whatever is specified by [XErrorSetOptions](/reference/system/xerror/functions/xerrorsetoptions); otherwise, return `false` to ignore the error.

## Remarks

Use the [XErrorSetCallback](/reference/system/xerror/functions/xerrorsetcallback) function to specify the `XErrorCallback` callback in your game that the system should call if an error occurs, and the `XErrorSetOptions` function to specify how the game should behave when an error occurs in the gaming OS or gaming runtime.

The following example illustrates how to set error options, define a custom error callback, and set the custom error callback to receive error notifications by the system.

```cpp theme={null}
bool CustomGameXErrorCallback(_In_ HRESULT hr, _In_ const char* msg, _In_ void* context)  
{  
   // Capture the error to the game's custom logger  
   CustomGameLogger* logger = (CustomGameLogger*)context;  
   logger->ReportGameRuntimeIssue(hr, msg);  
  
   // Don't ignore the error. For example, continue on and do whatever  
   // is specified by XErrorSetOptions().  
   return true;  
}  
  
void SomeGameFunction()  
{  
   // Previously initialize the game's custom logger  
   // CustomGameLogger* m_logger = InitializeLogger();  
   // ...  
  
   // Setup how you want to handle XErrors  
   XErrorSetOptions(DebugBreakOnError, FailFastOnError);
   XErrorSetCallback(CustomGameXErrorCallback, m_logger);
}  
```

## Requirements

**Header:** XError.h

**Library:** xgameruntime.lib

**Supported platforms:** Windows, XBOX One family consoles and XBOX Series consoles

## See also

[XError members](/reference/system/xerror/xerror_members)\
[XErrorSetCallback](/reference/system/xerror/functions/xerrorsetcallback)


## Related topics

- [XErrorSetCallback](/reference/system/xerror/functions/xerrorsetcallback.md)
- [XError members](/reference/system/xerror/xerror_members.md)
- [XMemCreateWin32Heap](/reference/system/xmem/functions/xmemcreatewin32heap.md)
- [WdCopyErrorCallback](/reference/remoting/callbacks/wdcopyerrorcallback.md)
- [XtfDebugStringErrorCallback](/reference/tools/xtf/xtfapi/functions/xtfdebugstringerrorcallback-xtfapi-xbox-windows-m.md)
