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

# XErrorSetCallback

> XErrorSetCallback

# XErrorSetCallback

ゲーミング OS またはゲーミング ランタイムでエラーが発生したときに呼び出されるコールバックを指定します。

## Syntax

```cpp theme={null}
void XErrorSetCallback(  
         XErrorCallback* callback,  
         void* context  
)  
```

### Parameters

*callback*   \_In\_\
型: XErrorCallback\*

呼び出すゲーム定義のコールバックへのポインター。`nullptr` を渡すとコールバックがクリアされます。

*context*   \_In\_\
型: void\*

コールバックのコンテキスト ポインター。

### Return value

型: void

## Remarks

<Note>この関数は、タイム センシティブ スレッドから呼び出しても安全ではありません。詳細については、[Time-sensitive threads](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads) を参照してください。</Note>

この関数を使用して、エラーが発生した場合にシステムが呼び出す必要のあるゲーム内の [XErrorCallback](/reference/system/xerror/functions/xerrorcallback) コールバックを指定し、[XErrorSetOptions](/reference/system/xerror/functions/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);
}  
```

## Requirements

**ヘッダー:** XError.h

**ライブラリ:** xgameruntime.lib

**サポートされているプラットフォーム:** Windows、XBOX One ファミリー本体および XBOX Series 本体

## Conceptual documentation

* [Time-sensitive threads](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)\
[XErrorCallback](/reference/system/xerror/functions/xerrorcallback)


## Related topics

- [XErrorCallback](/ja-jp/reference/system/xerror/functions/xerrorcallback.md)
- [XError members](/ja-jp/reference/system/xerror/xerror_members.md)
- [PartyManager::SetMemoryCallbacks](/ja-jp/services/playfab/multiplayer/networking/reference/classes/PartyManager/methods/partymanager_setmemorycallbacks.md)
- [XGameUiShowErrorDialogUiCallback](/ja-jp/reference/system/xgameui/functions/xgameuishowerrordialoguicallback.md)
- [PartyXblManager::SetMemoryCallbacks](/ja-jp/services/playfab/multiplayer/networking/xblreference/classes/PartyXblManager/methods/partyxblmanager_setmemorycallbacks.md)
