Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbb97e54

Browse files
committed
Fixes#194 -- show example of proper client usage and error handling.
1 parentb52fe01 commitbb97e54

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

‎libs/network/doc/reference/http_client.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,26 @@ happens on a different thread.
105105
dedicated to that request. The client does not re-cycle connections and uses
106106
a one-request-one-connection model.
107107

108+
When an asynchronous client object is destroyed, it waits for all pending
109+
asynchronous operations to finish. Errors encountered during operations on
110+
retrieving data from the response objects cause exceptions to be thrown --
111+
therefore it is best that if a client object is constructed, it should outlive
112+
the response object or be outside the try-catch block handling the errors from
113+
operations on responses. In code, usage should look like the following:
114+
115+
..code-block::c++
116+
117+
http::client client;
118+
try {
119+
http::client::response response = client.get("http://www.example.com/");
120+
std::cout << body(response);
121+
} catch (std::exception& e) {
122+
// deal with exceptions here
123+
}
124+
125+
A common mistake is to declare the client inside the try block which invokes
126+
undefined behavior when errors arise from the handling of response objects.
127+
108128
Member Functions
109129
----------------
110130

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp