> ## 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

在遊戲 OS 或遊戲執行階段發生錯誤時所呼叫的回呼。

## 語法

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

### 參數

*hr*   \_In\_\
類型：HRESULT

與錯誤相關聯的 HRESULT 代碼。

*msg*   \_In\_z\_\
類型：char\*

錯誤的文字描述。

*context*   \_In\_\
類型：void\*

回呼的內容指標。

### 傳回值

類型：bool

傳回 `true` 表示系統應繼續執行 [XErrorSetOptions](/zh-TW/reference/system/xerror/functions/xerrorsetoptions) 所指定的動作；否則傳回 `false` 以忽略錯誤。

## 備註

使用 [XErrorSetCallback](/zh-TW/reference/system/xerror/functions/xerrorsetcallback) 函式來指定遊戲中發生錯誤時系統應呼叫的 `XErrorCallback` 回呼，並使用 `XErrorSetOptions` 函式來指定遊戲 OS 或遊戲執行階段發生錯誤時遊戲應有的行為。

下列範例說明如何設定錯誤選項、定義自訂錯誤回呼，以及設定自訂錯誤回呼以接收系統的錯誤通知。

```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);
}  
```

## 需求

**標頭：** XError.h

**程式庫：** xgameruntime.lib

**支援的平台：** Windows、XBOX One 系列主機和 XBOX Series 主機

## 另請參閱

[XError 成員](/zh-TW/reference/system/xerror/xerror_members)\
[XErrorSetCallback](/zh-TW/reference/system/xerror/functions/xerrorsetcallback)


## Related topics

- [XErrorCallback](/reference/system/xerror/functions/xerrorcallback.md)
- [XErrorSetCallback](/reference/system/xerror/functions/xerrorsetcallback.md)
