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

# XErrorSetOptions

> XErrorSetOptions

# XErrorSetOptions

指定在遊戲 OS 或遊戲執行階段發生錯誤時所需的行為。

## 語法

```cpp theme={null}
void XErrorSetOptions(  
         XErrorOptions optionsDebuggerPresent,  
         XErrorOptions optionsDebuggerNotPresent  
)  
```

### 參數

*optionsDebuggerPresent*   \_In\_\
類型：[XErrorOptions](/zh-TW/reference/system/xerror/enums/xerroroptions)

指定附加偵錯工具時所需的行為。

*optionsDebuggerNotPresent*   \_In\_\
類型：[XErrorOptions](/zh-TW/reference/system/xerror/enums/xerroroptions)

指定未附加偵錯工具時所需的行為。

### 傳回值

類型：void

## 備註

<Note>在時間敏感的執行緒上呼叫此函式並不安全。如需詳細資訊，請參閱[時間敏感的執行緒](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads)。</Note>

使用此函式來指定遊戲 OS 或遊戲執行階段發生錯誤時遊戲應如何回應。根據預設，若未附加偵錯工具，遊戲不會執行任何動作；若已附加偵錯工具，則會將偵錯訊息輸出至偵錯工具。

如果已附加偵錯工具，且 *optionsDebuggerPresent* 設定為 \[XErrorOptions::DebugBreakOnError]，系統會中斷進入偵錯工具並輸出偵錯訊息。您可以透過監看式視窗將全域變數 `XErrorDisableDebugBreak` 的值設定為 `true`，以暫時停用此行為。

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

```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 主機

## 概念文件

* [時間敏感的執行緒](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads)

## 另請參閱

[XError 成員](/zh-TW/reference/system/xerror/xerror_members)\
[XErrorOptions](/zh-TW/reference/system/xerror/enums/xerroroptions)


## Related topics

- [XErrorSetOptions](/reference/system/xerror/functions/xerrorsetoptions.md)
- [XErrorOptions](/reference/system/xerror/enums/xerroroptions.md)
