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

# 处理 Lobby 和 Matchmaking C++ SDK 错误

> PlayFab Lobby 和 Matchmaking C++ SDK 呈现的同步和异步错误(包括 HRESULT 代码和错误消息)的处理参考。

# 处理 Lobby 和 Matchmaking SDK 错误

本页旨在作为 PlayFab Lobby 和 Matchmaking SDK 如何呈现错误以及你应如何处理它们的快速参考指南。

将讨论以下主题:

* [同步与异步错误](#synchronous-vs-asynchronous-errors)
* [错误代码和错误消息](#error-codes-and-error-messages)

## 同步与异步错误

许多 SDK API 都是异步的。你通过调用类似 [PFMultiplayerCreateAndJoinLobby](/services/playfab/multiplayer/lobby/playfabmultiplayerreference-cpp/pflobby/functions/pfmultiplayercreateandjoinlobby) 的 API 来启动一个操作,稍后该异步操作会通过“状态变更”(例如 [PFLobbyCreateAndJoinLobbyCompletedStateChange](/services/playfab/multiplayer/lobby/playfabmultiplayerreference-cpp/pflobby/structs/pflobbycreateandjoinlobbycompletedstatechange))完成。

这意味着,当使用异步 Lobby 和 Matchmaking 客户端 API 时,你必须处理两种类型的错误:

1. 同步错误
2. 异步错误

有关 SDK 的异步模型和状态变更的更多信息,请参阅[异步操作](/services/playfab/multiplayer/lobby/lobby-and-matchmaking-client-sdk-async)文档页面。

对于同步 API(例如 [PFLobbyGetLobbyId](/services/playfab/multiplayer/lobby/playfabmultiplayerreference-cpp/pflobby/functions/pflobbygetlobbyid)),你只需要处理同步错误。

### 同步错误

“同步错误”是作为 API 调用返回值提供的 **HRESULT**。这些错误通常是由于以下原因引起的:使用不正确的参数调用 API、在库处于无效状态时调用 API,或者库内部无法分配内存。如果 API 返回同步错误,则 API 提供的任何输出参数都应视为无效。

在调用异步 API 时(例如 **PFMultiplayerCreateAndJoinLobby**),同步错误值仅表示请求的操作是否能够开始。有关理解异步操作结果的信息,请参阅[异步错误](#asynchronous-errors)部分。

### 异步错误

“异步错误”作为与每个操作异步完成相关的状态变更中的 **HRESULT** 提供,即 *result* 字段。这些错误对游戏来说通常比同步错误更值得关注。异步报告的一些错误类型的非详尽列表包括:

* 服务限流错误
* 无法在客户端同步验证的无效参数错误
* 与实时消息服务交互的错误
* 连接错误

有关获取异步和同步错误的可读错误消息的指导,请参阅[错误代码和错误消息](#error-codes-and-error-messages)部分。

## 错误代码和错误消息

错误(无论同步还是异步)由库以 HRESULT 的形式呈现:一个四字节的数值错误代码。这些紧凑的错误代码非常适合记录在遥测和其他用于调试意外游戏行为的诊断工具中。

可以通过调用 [PFMultiplayerGetErrorMessage](/services/playfab/multiplayer/lobby/playfabmultiplayerreference-cpp/pfmultiplayer/functions/pfmultiplayergeterrormessage) 将这些错误代码转换为可读消息。这些错误消息仅供开发人员查看。它们没有本地化,也不打算供最终用户消费,因此最适合用于内部开发日志。

此外,可以在 [PlayFab Multiplayer SDK 错误代码](/services/playfab/multiplayer/lobby/playfabmultiplayerreference-cpp/pfmultiplayererrors)中获取 SDK 错误代码及其错误消息的列表。


## Related topics

- [异步 Lobby 和 Matchmaking C++ SDK 操作指南](/zh-CN/services/playfab/multiplayer/lobby/lobby-and-matchmaking-client-sdk-async.md)
- [PlayFab Lobby 和 Matchmaking SDK](/zh-CN/services/playfab/multiplayer/lobby/lobby-matchmaking-sdks/lobby-matchmaking-sdks.md)
- [PlayFab Lobby 和 Matchmaking SDK 中的诊断跟踪](/zh-CN/services/playfab/multiplayer/lobby/lobby-matchmaking-sdks/lobby-matchmaking-logging.md)
- [PlayFab Multiplayer C++ SDK 发行说明](/zh-CN/services/playfab/multiplayer/lobby/lobby-matchmaking-sdks/lobby-and-matchmaking-release-notes.md)
- [处理常见错误情形](/zh-CN/services/playfab/multiplayer/matchmaking/error-cases.md)
