> ## 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 或游戏运行时出现错误时的所需行为。

## Syntax

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

### Parameters

*optionsDebuggerPresent*   \_In\_\
类型：[XErrorOptions](/reference/system/xerror/enums/xerroroptions)

指定附加调试器时的所需行为。

*optionsDebuggerNotPresent*   \_In\_\
类型：[XErrorOptions](/reference/system/xerror/enums/xerroroptions)

指定未附加调试器时的所需行为。

### Return value

类型：void

## Remarks

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

## Requirements

**头文件：** XError.h

**库：** xgameruntime.lib

**受支持的平台：** Windows、XBOX One 系列主机和 XBOX Series 主机

## Conceptual documentation

* [时间敏感线程](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads)

## See also

[XError members](/reference/system/xerror/xerror_members)\
[XErrorOptions](/reference/system/xerror/enums/xerroroptions)


## Related topics

- [XErrorOptions](/zh-CN/reference/system/xerror/enums/xerroroptions.md)
- [XErrorCallback](/zh-CN/reference/system/xerror/functions/xerrorcallback.md)
- [XError members](/zh-CN/reference/system/xerror/xerror_members.md)
- [XErrorSetCallback](/zh-CN/reference/system/xerror/functions/xerrorsetcallback.md)
- [XMemSetOption](/zh-CN/reference/system/xmem/functions/xmemsetoption.md)
