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

# Handling Lobby and Matchmaking C++ SDK errors

> Reference for handling synchronous and asynchronous errors surfaced by the PlayFab Lobby and Matchmaking C++ SDK, including HRESULT codes and error messages.

# Handling Lobby and Matchmaking SDK errors

This page intends to serve as a quick reference for guidance on how the PlayFab Lobby and Matchmaking SDKs
surface errors and how you should handle them.

The following topics are discussed:

* [Synchronous vs asynchronous errors](#synchronous-vs-asynchronous-errors)
* [Error codes and error messages](#error-codes-and-error-messages)

## Synchronous vs asynchronous errors

Many SDK APIs are asynchronous. You start an operation by calling an API like
[PFMultiplayerCreateAndJoinLobby](/services/playfab/multiplayer/lobby/playfabmultiplayerreference-cpp/pflobby/functions/pfmultiplayercreateandjoinlobby)
and later that asynchronous operation completes with a "state change" like [PFLobbyCreateAndJoinLobbyCompletedStateChange](/services/playfab/multiplayer/lobby/playfabmultiplayerreference-cpp/pflobby/structs/pflobbycreateandjoinlobbycompletedstatechange).

This means, when using asynchronous Lobby and Matchmaking Client APIs, there are two types of errors that you must handle:

1. synchronous errors
2. asynchronous errors

More information on the SDK's async model and state changes can be found on the
[async operations](/services/playfab/multiplayer/lobby/lobby-and-matchmaking-client-sdk-async) doc page.

For synchronous APIs, such as [PFLobbyGetLobbyId](/services/playfab/multiplayer/lobby/playfabmultiplayerreference-cpp/pflobby/functions/pflobbygetlobbyid),
you only need to handle synchronous errors.

### Synchronous errors

"Synchronous errors" are **HRESULTs** provided as the return value of an API call. These errors are generally due to
calling the API with incorrect parameters, calling the API while the library is in an invalid state, or internal library
failures to allocate memory. Any output parameters provided by the API should be considered invalid if the API returns
a synchronous error.

When calling asynchronous APIs (e.g. **PFMultiplayerCreateAndJoinLobby**), the synchronous error value only
represents whether the requested operation was able to start. For information on understanding the result of an
asynchronous operation, see the [Asynchronous errors](#asynchronous-errors) section.

### Asynchronous errors

"Asynchronous errors" are provided as **HRESULTs** in the state change associated with the
asynchronous completion of each operation, the *result* field. These errors are typically more interesting to titles
than synchronous errors. A non-exhaustive list of some of the types of errors reported asynchronously include:

* service throttling errors
* invalid parameter errors that can't be validated synchronously on the client
* errors interacting with the real-time message service
* connectivity errors

See the [Error codes and error messages](#error-codes-and-error-messages) section for guidance on getting human-readable
error messages for both asynchronous and synchronous errors.

## Error codes and error messages

Errors (whether synchronous or asynchronous) are presented by the library in the form of an HRESULT: a four byte
numeric error code. These compact error codes are ideal for recording in telemetry and other diagnostic tools used to
debug unexpected title behavior.

These error codes can be converted to a human-readable message by calling [PFMultiplayerGetErrorMessage](/services/playfab/multiplayer/lobby/playfabmultiplayerreference-cpp/pfmultiplayer/functions/pfmultiplayergeterrormessage).
These error messages are intended to only be looked at by developers. They are not localized or intended for consumption
by end users, so are best suited for internal development logs.

Additionally a list of the SDK's error codes with their error messages are available at
[PlayFab Multiplayer SDK Error Codes](/services/playfab/multiplayer/lobby/playfabmultiplayerreference-cpp/pfmultiplayererrors).


## Related topics

- [PlayFab Multiplayer C++ SDK Error Codes](/services/playfab/multiplayer/lobby/playfabmultiplayerreference-cpp/pfmultiplayererrors.md)
- [Async Lobby and Matchmaking C++ SDK operations guide](/services/playfab/multiplayer/lobby/lobby-and-matchmaking-client-sdk-async.md)
- [SDK error handling Best Practices](/services/playfab/live-service-management/service-gateway/automation/cloudscript/sdk-error-handling-best-practices.md)
- [PlayFab Lobby and Matchmaking SDKs](/services/playfab/multiplayer/lobby/lobby-matchmaking-sdks/lobby-matchmaking-sdks.md)
- [Diagnostic tracing in PlayFab Lobby and Matchmaking SDKs](/services/playfab/multiplayer/lobby/lobby-matchmaking-sdks/lobby-matchmaking-logging.md)
