Skip to content

Commit a5fd3b9

Browse files
committed
Minor restructuring
1 parent 7dc1e9b commit a5fd3b9

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

lectures/error_handling.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -330,13 +330,6 @@ std::expected<std::string, std::string> GetAnswerFromLlm(const std::string& ques
330330
}
331331
```
332332

333-
This has all the benefits we mentioned before:
334-
335-
- The signature of our function clearly states that it might fail
336-
- The error if it happens needs to be dealt with explicitly by the caller
337-
- Everything happens in deterministic time with no RTTI overhead
338-
- Works for functions returning `void` too
339-
340333
Using it is also quite neat:
341334

342335
```cpp
@@ -350,6 +343,13 @@ int main() {
350343
}
351344
```
352345

346+
This has all the benefits we mentioned before:
347+
348+
- The signature of our function clearly states that it might fail
349+
- The error if it happens needs to be dealt with explicitly by the caller
350+
- Everything happens in deterministic time with no unpredictable runtime overhead
351+
- Works for functions returning `void` too
352+
353353
There is just one tiny issue that spoils our fun. As you've probably noticed, most of the things we covered until now targeted C++17, and `std::expected` is only available from C++23 on. But there is a solution to this: we can use [`tl::expected`](https://github.com/TartanLlama/expected) as a drop-in replacement for code bases that don't yet adopt C++23.
354354

355355
## Performance Considerations for `std::optional` and `std::expected`

0 commit comments

Comments
 (0)