mirror of
https://github.com/simonbrunel/qtpromise.git
synced 2025-07-08 02:08:13 +08:00
- Fix the wrong lambda format (missing `[]`). - Make consistent argument naming (`error`). - Use `const &` when appropriated.
29 lines
577 B
Markdown
29 lines
577 B
Markdown
---
|
|
title: .fail
|
|
---
|
|
|
|
# QPromise::fail
|
|
|
|
*Since: 0.1.0*
|
|
|
|
```cpp
|
|
QPromise<T>::fail(Function onRejected) -> QPromise<T>
|
|
```
|
|
|
|
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& error) {
|
|
// {...}
|
|
}).fail([](const QException& error) {
|
|
// {...}
|
|
}).fail([](const std::exception& error) {
|
|
// {...}
|
|
}).fail([]() {
|
|
// {...} catch-all
|
|
});
|
|
```
|
|
|
|
See also: [`QPromise::then`](then.md)
|