mirror of
https://github.com/simonbrunel/qtpromise.git
synced 2024-11-24 11:40:41 +08:00
Fix docs C++ snippet for the .fail()
args
- Fix the wrong lambda format (missing `[]`). - Make consistent argument naming (`error`). - Use `const &` when appropriated.
This commit is contained in:
parent
3c1461b8d0
commit
cc29ef3512
@ -7,7 +7,7 @@ canceled (e.g. using [`QFuture::cancel()`](http://doc.qt.io/qt-5/qfuture.html#ca
|
||||
|
||||
```cpp
|
||||
auto output = QtPromise::resolve(future)
|
||||
.fail([](const QPromiseCanceledException&) {
|
||||
.fail([](const QPromiseCanceledException& error) {
|
||||
// `future` has been canceled!
|
||||
});
|
||||
```
|
||||
|
@ -8,7 +8,7 @@ This is the default exception thrown when reaching the time limit when using the
|
||||
```cpp
|
||||
QPromise<int> input = {...}
|
||||
auto output = input.timeout(2000)
|
||||
.fail([](const QPromiseTimeoutException& e) {
|
||||
.fail([](const QPromiseTimeoutException& error) {
|
||||
// operation timed out after 2s!
|
||||
});
|
||||
```
|
||||
|
@ -90,9 +90,9 @@ download(url).then(&uncompress).then([](const Entries& entries) {
|
||||
// {...} process entries
|
||||
}).finally([]() {
|
||||
// {...} cleanup
|
||||
}).fail([](QNetworkReply::NetworkError err) {
|
||||
}).fail([](QNetworkReply::NetworkError error) {
|
||||
// {...} handle network error
|
||||
}).fail([](const UpdateException& err) {
|
||||
}).fail([](const UpdateException& error) {
|
||||
// {...} handle update error
|
||||
}).fail([]() {
|
||||
// {...} catch all
|
||||
|
@ -41,7 +41,7 @@ auto output = process(url);
|
||||
// 'output' type: QPromise<QByteArray>
|
||||
output.then([](const QByteArray& res) {
|
||||
// {...}
|
||||
}).fail([](const InvalidUrlException& err) {
|
||||
}).fail([](const InvalidUrlException& error) {
|
||||
// {...}
|
||||
});
|
||||
```
|
||||
|
@ -42,9 +42,9 @@ auto output = QtPromise::connect(sender, &Sender::finished, &Sender::error);
|
||||
// 'output' type: QPromise<QByteArray>
|
||||
output.then([](const QByteArray& res) {
|
||||
// 'res' is the first argument of the 'finished' signal.
|
||||
}).fail([](ErrorCode err) {
|
||||
// 'err' is the first argument of the 'error' signal.
|
||||
}).fail([](const QPromiseContextException& err) {
|
||||
}).fail([](ErrorCode error) {
|
||||
// 'error' is the first argument of the 'error' signal.
|
||||
}).fail([](const QPromiseContextException& error) {
|
||||
// the 'sender' object has been destroyed before any of
|
||||
// the 'finished' or 'error' signals have been emitted.
|
||||
});
|
||||
|
@ -10,16 +10,19 @@ title: .fail
|
||||
QPromise<T>::fail(Function onRejected) -> QPromise<T>
|
||||
```
|
||||
|
||||
Shorthand to `promise.then(nullptr, onRejected)`, similar to the [`catch` statement](http://en.cppreference.com/w/cpp/language/try_catch):
|
||||
Shorthand to [`promise.then(nullptr, onRejected)`](then.md) for handling errors in promise chains,
|
||||
similar to the native C++ [`catch` statement](http://en.cppreference.com/w/cpp/language/try_catch):
|
||||
|
||||
```cpp
|
||||
promise.fail([](const MyException&) {
|
||||
promise.fail([](const MyException& error) {
|
||||
// {...}
|
||||
}).fail(const QException&) {
|
||||
}).fail([](const QException& error) {
|
||||
// {...}
|
||||
}).fail(const std::exception&) {
|
||||
}).fail([](const std::exception& error) {
|
||||
// {...}
|
||||
}).fail() {
|
||||
}).fail([]() {
|
||||
// {...} catch-all
|
||||
});
|
||||
```
|
||||
|
||||
See also: [`QPromise::then`](then.md)
|
||||
|
@ -17,12 +17,12 @@ rejected with the new exception.
|
||||
|
||||
```cpp
|
||||
QPromise<int> input = {...}
|
||||
auto output = input.tapFail([](Error err) {
|
||||
log(err);
|
||||
auto output = input.tapFail([](const Error& error) {
|
||||
log(error);
|
||||
}).then([](int res) {
|
||||
return process(res);
|
||||
}).fail([](Error err) {
|
||||
handle(err);
|
||||
}).fail([](const Error& error) {
|
||||
handle(error);
|
||||
return -1;
|
||||
});
|
||||
```
|
||||
|
@ -21,7 +21,7 @@ auto output = input.timeout(2000)
|
||||
.then([](int res) {
|
||||
// operation succeeded within 2 seconds
|
||||
})
|
||||
.fail([](const QPromiseTimeoutException& e) {
|
||||
.fail([](const QPromiseTimeoutException& error) {
|
||||
// operation timed out!
|
||||
});
|
||||
```
|
||||
|
@ -67,7 +67,7 @@ promise.then([](int res) {
|
||||
|
||||
return QString("42");
|
||||
});
|
||||
}).fail(const CustomException& err) {
|
||||
}).fail([](const CustomException& error) {
|
||||
// {...}
|
||||
});
|
||||
```
|
||||
|
@ -53,7 +53,7 @@ auto output = QtPromise::connect(obj, &Object::finished, &Object::error);
|
||||
// output type: QPromise<QByteArray>
|
||||
output.then([](const QByteArray& data) {
|
||||
// {...}
|
||||
}).fail(const ObjectError& error) {
|
||||
}).fail([](const ObjectError& error) {
|
||||
// {...}
|
||||
});
|
||||
```
|
||||
@ -69,7 +69,7 @@ auto output = QtPromise::connect(obj, &Object::finished, &Object::error);
|
||||
// output type: QPromise<QByteArray>
|
||||
output.then([]() {
|
||||
// {...}
|
||||
}).fail(const QPromiseUndefinedException& error) {
|
||||
}).fail([](const QPromiseUndefinedException& error) {
|
||||
// {...}
|
||||
});
|
||||
```
|
||||
@ -84,7 +84,7 @@ auto output = QtPromise::connect(objA, &ObjectA::finished, objB, &ObjectB::error
|
||||
// output type: QPromise<QByteArray>
|
||||
output.then([](const QByteArray& data) {
|
||||
// {...}
|
||||
}).fail(const ObjectBError& error) {
|
||||
}).fail([](const ObjectBError& error) {
|
||||
// {...}
|
||||
});
|
||||
```
|
||||
|
Loading…
Reference in New Issue
Block a user