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

<a id="synchronous-vs-asynchronous-errors" />

## 同步與非同步錯誤

許多 SDK API 都是非同步的。您可以呼叫 [PFMultiplayerCreateAndJoinLobby](/zh-TW/services/playfab/multiplayer/lobby/playfabmultiplayerreference-cpp/pflobby/functions/pfmultiplayercreateandjoinlobby) 之類的 API 來啟動作業，稍後該非同步作業會以 [PFLobbyCreateAndJoinLobbyCompletedStateChange](/zh-TW/services/playfab/multiplayer/lobby/playfabmultiplayerreference-cpp/pflobby/structs/pflobbycreateandjoinlobbycompletedstatechange) 之類的「狀態變更」完成。

這表示在使用非同步 Lobby 和 Matchmaking 用戶端 API 時，您必須處理兩種類型的錯誤：

1. 同步錯誤
2. 非同步錯誤

如需 SDK 非同步模型和狀態變更的詳細資訊，請參閱[非同步作業](/zh-TW/services/playfab/multiplayer/lobby/lobby-and-matchmaking-client-sdk-async)文件頁面。

對於同步 API，例如 [PFLobbyGetLobbyId](/zh-TW/services/playfab/multiplayer/lobby/playfabmultiplayerreference-cpp/pflobby/functions/pflobbygetlobbyid)，您只需要處理同步錯誤。

### 同步錯誤

「同步錯誤」是作為 API 呼叫傳回值提供的 **HRESULT**。這些錯誤通常是由於以不正確的參數呼叫 API、在程式庫處於無效狀態時呼叫 API，或程式庫內部配置記憶體失敗所致。如果 API 傳回同步錯誤，則應將 API 提供的任何輸出參數視為無效。

呼叫非同步 API (例如 **PFMultiplayerCreateAndJoinLobby**) 時，同步錯誤值只代表要求的作業是否能夠啟動。如需了解非同步作業結果的資訊，請參閱[非同步錯誤](#asynchronous-errors)一節。

<a id="asynchronous-errors" />

### 非同步錯誤

「非同步錯誤」是以 **HRESULT** 的形式，提供在與每個作業之非同步完成相關聯之狀態變更的 *result* 欄位中。遊戲通常對這些錯誤比對同步錯誤更感興趣。以非同步方式回報的部分錯誤類型 (非詳盡清單) 包括：

* 服務節流錯誤
* 無法在用戶端上同步驗證的無效參數錯誤
* 與即時訊息服務互動時的錯誤
* 連線錯誤

如需取得非同步和同步錯誤之人類可讀錯誤訊息的指引，請參閱[錯誤碼和錯誤訊息](#error-codes-and-error-messages)一節。

<a id="error-codes-and-error-messages" />

## 錯誤碼和錯誤訊息

錯誤 (無論是同步還是非同步) 由程式庫以 HRESULT 的形式呈現：一個四位元組的數字錯誤碼。這些精簡的錯誤碼非常適合記錄在遙測和其他用於偵錯非預期遊戲行為的診斷工具中。

可以呼叫 [PFMultiplayerGetErrorMessage](/zh-TW/services/playfab/multiplayer/lobby/playfabmultiplayerreference-cpp/pfmultiplayer/functions/pfmultiplayergeterrormessage) 將這些錯誤碼轉換為人類可讀的訊息。這些錯誤訊息只供開發人員查看。它們未經當地語系化，也不適合讓終端使用者閱讀，因此最適合用於內部開發記錄。

此外，SDK 的錯誤碼及其錯誤訊息清單可在 [PlayFab Multiplayer SDK 錯誤碼](/zh-TW/services/playfab/multiplayer/lobby/playfabmultiplayerreference-cpp/pfmultiplayererrors)中取得。


## Related topics

- [非同步 Lobby 和 Matchmaking C++ SDK 作業指南](/zh-TW/services/playfab/multiplayer/lobby/lobby-and-matchmaking-client-sdk-async.md)
- [PlayFab Lobby 和 Matchmaking SDK](/zh-TW/services/playfab/multiplayer/lobby/lobby-matchmaking-sdks/lobby-matchmaking-sdks.md)
- [PlayFab Lobby 和 Matchmaking SDK 中的診斷追蹤](/zh-TW/services/playfab/multiplayer/lobby/lobby-matchmaking-sdks/lobby-matchmaking-logging.md)
- [處理常見錯誤案例](/zh-TW/services/playfab/multiplayer/matchmaking/error-cases.md)
- [Lobby 和 Matchmaking 即時訊息](/zh-TW/services/playfab/multiplayer/lobby/lobby-and-matchmaking-real-time-messages.md)
