Add documentation for built-in exceptions

This commit is contained in:
Simon Brunel 2019-02-01 16:06:29 +01:00
parent fa5a4192ff
commit 9119cc72f6
7 changed files with 79 additions and 2 deletions

View File

@ -52,6 +52,14 @@ module.exports = {
'qtpromise/helpers/qpromise', 'qtpromise/helpers/qpromise',
'qtpromise/helpers/qpromiseall' 'qtpromise/helpers/qpromiseall'
] ]
},
{
title: 'Exceptions',
children: [
'qtpromise/exceptions/canceled',
'qtpromise/exceptions/timeout',
'qtpromise/exceptions/undefined'
]
} }
] ]
} }

View File

@ -32,3 +32,9 @@
* [`QtPromise::map`](helpers/map.md) * [`QtPromise::map`](helpers/map.md)
* [`qPromise`](helpers/qpromise.md) * [`qPromise`](helpers/qpromise.md)
* [`qPromiseAll`](helpers/qpromiseall.md) * [`qPromiseAll`](helpers/qpromiseall.md)
## Exceptions
* [`QPromiseCanceledException`](exceptions/canceled.md)
* [`QPromiseTimeoutException`](exceptions/timeout.md)
* [`QPromiseUndefinedException`](exceptions/undefined.md)

View File

@ -0,0 +1,19 @@
---
title: QPromiseCanceledException
---
# QPromiseCanceledException
*Since: 0.1.0*
This exception is thrown for promise created from a [`QFuture`](../qtconcurrent.md)
which has been canceled (e.g. using [`QFuture::cancel()`](http://doc.qt.io/qt-5/qfuture.html#cancel)).
Note that QtPromise doesn't support promise cancelation yet. For example:
```cpp
auto output = qPromise(future)
.fail([](const QPromiseCanceledException&) {
// `future` has been canceled!
});
```

View File

@ -0,0 +1,18 @@
---
title: QPromiseTimeoutException
---
# QPromiseTimeoutException
*Since: 0.2.0*
This is the default exception thrown when reaching the time limit when using
the [`QPromise::timeout()`](../qpromise/timeout.md) method, for example:
```cpp
QPromise<int> input = {...}
auto output = input.timeout(2000)
.fail([](const QPromiseTimeoutException& e) {
// operation timed out after 2s!
});
```

View File

@ -0,0 +1,26 @@
---
title: QPromiseUndefinedException
---
# QPromiseUndefinedException
*Since: 0.5.0*
This exception is thrown when rejecting a promise with no explicit reason, for
example:
```cpp
QPromise<int> promise([](const QPromiseResolve<int>& resolve, const QPromiseReject<int>& reject) {
async_method([=](bool success, int result) {
if (success) {
resolve(result);
} else {
reject();
}
});
});
promise.fail([](const QPromiseUndefinedException&) {
// promise rejected without reason!
})
```

View File

@ -42,7 +42,7 @@ QPromise<int> promise([](const auto& resolve, const auto& reject) {
While not recommended because it makes tracking errors more difficult, it's also While not recommended because it makes tracking errors more difficult, it's also
possible to reject a promise without explicit reason, in which case, a built-in possible to reject a promise without explicit reason, in which case, a built-in
`QPromiseUndefinedException` is thrown: [`QPromiseUndefinedException`](../exceptions/undefined.md) is thrown:
```cpp ```cpp
QPromise<int> promise([](const QPromiseResolve<int>& resolve, const QPromiseReject<int>& reject) { QPromise<int> promise([](const QPromiseResolve<int>& resolve, const QPromiseReject<int>& reject) {

View File

@ -10,7 +10,7 @@ title: .timeout
QPromise<T>::timeout(int msec, any error = QPromiseTimeoutException) -> QPromise<T> QPromise<T>::timeout(int msec, any error = QPromiseTimeoutException) -> QPromise<T>
``` ```
This method returns a promise that will be resolved with the `input` promise's fulfillment value or rejection reason. However, if the `input` promise is not fulfilled or rejected within `msec` milliseconds, the `output` promise is rejected with `error` as the reason (`QPromiseTimeoutException` by default). This method returns a promise that will be resolved with the `input` promise's fulfillment value or rejection reason. However, if the `input` promise is not fulfilled or rejected within `msec` milliseconds, the `output` promise is rejected with `error` as the reason ([`QPromiseTimeoutException`](../exceptions/timeout.md) by default).
```cpp ```cpp
QPromise<int> input = {...} QPromise<int> input = {...}