Skip to content

Commit 25c3c56

Browse files
committed
Final changes to readme and text
1 parent d78a588 commit 25c3c56

File tree

2 files changed

+44
-11
lines changed

2 files changed

+44
-11
lines changed

lectures/error_handling.md

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
**Error Handling in C++**
33

44
<p align="center">
5-
<a href="https://youtu.be/dummy_link"><img src="https://img.youtube.com/vi/dummy_link/maxresdefault.jpg" alt="Video Thumbnail" align="right" width=50% style="margin: 0.5rem"></a>
5+
<a href="https://youtu.be/6DqX8OJKM1g"><img src="https://img.youtube.com/vi/6DqX8OJKM1g/maxresdefault.jpg" alt="Video Thumbnail" align="right" width=50% style="margin: 0.5rem"></a>
66
</p>
77

88
- [Disclaimer](#disclaimer)
@@ -45,10 +45,6 @@ So get a coffee and buckle up! There is a lot to cover and quite some nuance in
4545

4646
Ah, and I can already smell the torches and hear the scraping of the pitchforks that people will inevitably bring to punish me for all the controversial statements I am about to make! What can go wrong, eh?
4747

48-
<!-- Add a video from shreck?
49-
Link: https://www.youtube.com/watch?v=Waa9UqVP4KI
50-
-->
51-
5248
# Disclaimer
5349

5450
Jokes aside, this is definitely *not* a one-size-fits-all topic. C++ is huge, powerful, and used across every domain imaginable for a long-long time.
@@ -63,8 +59,6 @@ However, I believe that what we talk about today fits many setups with minimal a
6359
6460
Now, back to error handling. -->
6561

66-
<!-- TODO: Film the camera that films me, slowly zooming in. -->
67-
6862
# What Do We Mean by “Error”?
6963

7064
Before we go into how to handle errors, however, let’s clarify what we mean when we think about an "error" in programming.
@@ -227,7 +221,7 @@ Budget: 10
227221
Reference numbers: 42 49 23
228222
Player numbers: 10 40 24
229223
Please enter number to change: 40
230-
Please provide a a new value: 49
224+
Please provide a new value: 50
231225
Budget: 2
232226
Reference numbers: 50 49 23
233227
Player numbers: 10 40 24
@@ -341,7 +335,7 @@ If we run our example now, we will get a crash as soon as we call the `ChangePla
341335
F0000 00:00:1750605447.566908 1 example.cpp:44] Check failed: change_entry.index < player_numbers_.size() (40 vs. 3)
342336
```
343337

344-
To the degree of my knowledge, using `CHECK`-like macros to check pre-conditions of functions is widely considered a good practice. These `CHECK`s can be violated either due to a bug in our program or due to some undefined behavior just like in our example from earlier.
338+
To the degree of my knowledge, using `CHECK`-like macros to check pre-conditions of functions is [widely considered a good practice](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#i6-prefer-expects-for-expressing-preconditions). These `CHECK`s can be violated either due to a bug in our program or due to some undefined behavior just like in our example from earlier.
345339

346340
One concern that people have when thinking of using the `CHECK` macros is performance as these checks stay in the production code we ship and do cost some little time when our program runs.
347341

@@ -428,8 +422,6 @@ c++ -std=c++17 -DNDEBUG -o comparison_game comparison_game.cpp
428422

429423
Running our game *now* and providing a wrong input index leads to the same undefined behavior we observed before as all of the assertions were compiled out. Not great, right? What makes it even less great is that many people just don't know that `asserts` get disabled like that and are sure that they are protected, while they really are not!
430424

431-
<!-- Get the UB kick assert's ass, and me pushing the UB away -->
432-
433425
And `CHECK` does not have these flaws.
434426

435427
### Complete the `Game` class yourself

readme.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,47 @@ Headers with classes
721721
----------------------------------------------------------
722722
</details>
723723

724+
<details>
725+
<summary>Error handling in C++</summary>
726+
727+
----------------------------------------------------------
728+
[![Video thumbnail](https://img.youtube.com/vi/6DqX8OJKM1g/maxresdefault.jpg)](https://youtu.be/6DqX8OJKM1g)
729+
730+
- [Disclaimer](#disclaimer)
731+
- [What Do We Mean by “Error”?](lectures/error_handling.md#what-do-we-mean-by-error)
732+
- [Setting up the example: **a comparison game**](lectures/error_handling.md#setting-up-the-example-a-comparison-game)
733+
- [Rules of the game](lectures/error_handling.md#rules-of-the-game)
734+
- [Initial code of the game](lectures/error_handling.md#initial-code-of-the-game)
735+
- [Unrecoverable errors: **fail early**](lectures/error_handling.md#unrecoverable-errors-fail-early)
736+
- [Our first unrecoverable error encounter](lectures/error_handling.md#our-first-unrecoverable-error-encounter)
737+
- [How to deal with unrecoverable errors](lectures/error_handling.md#how-to-deal-with-unrecoverable-errors)
738+
- [Catch them as early as possible](lectures/error_handling.md#catch-them-as-early-as-possible)
739+
- [Use `CHECK` macro to fail early](lectures/error_handling.md#use-check-macro-to-fail-early)
740+
- [Don't use `assert`](lectures/error_handling.md#dont-use-assert)
741+
- [Complete the `Game` class yourself](lectures/error_handling.md#complete-the-game-class-yourself)
742+
- [How to minimize number of unrecoverable errors](lectures/error_handling.md#how-to-minimize-number-of-unrecoverable-errors)
743+
- [Recoverable errors: **handle and proceed**](lectures/error_handling.md#recoverable-errors-handle-and-proceed)
744+
- [Exceptions](lectures/error_handling.md#exceptions)
745+
- [How to use exceptions](lectures/error_handling.md#how-to-use-exceptions)
746+
- [A case for exceptions for both "recoverable" and "unrecoverable" errors](lectures/error_handling.md#a-case-for-exceptions-for-both-recoverable-and-unrecoverable-errors)
747+
- [Why we might not want to use exceptions](lectures/error_handling.md#why-we-might-not-want-to-use-exceptions)
748+
- [Exceptions are (sometimes) expensive](lectures/error_handling.md#exceptions-are-sometimes-expensive)
749+
- [Exceptions hide the error path](lectures/error_handling.md#exceptions-hide-the-error-path)
750+
- [Exceptions are banned in many code bases](lectures/error_handling.md#exceptions-are-banned-in-many-code-bases)
751+
- [Returning errors explicitly can work better if done well](lectures/error_handling.md#returning-errors-explicitly-can-work-better-if-done-well)
752+
- [Returning a value indicating error does not always work 😱](lectures/error_handling.md#returning-a-value-indicating-error-does-not-always-work-)
753+
- [Returning an error code breaks "pure functions" 😱](lectures/error_handling.md#returning-an-error-code-breaks-pure-functions-)
754+
- [Using `std::optional`: **a better way**](lectures/error_handling.md#using-stdoptional-a-better-way)
755+
- [Using `std::expected`: **add context**](lectures/error_handling.md#using-stdexpected-add-context)
756+
- [Performance Considerations for `std::optional` and `std::expected`](lectures/error_handling.md#performance-considerations-for-stdoptional-and-stdexpected)
757+
- [Error type size matters](lectures/error_handling.md#error-type-size-matters)
758+
- [Return value optimization with `std::optional` and `std::expected`](lectures/error_handling.md#return-value-optimization-with-stdoptional-and-stdexpected)
759+
- [Summary](lectures/error_handling.md#summary)
760+
- [Other use of `std::optional`](lectures/error_handling.md#other-use-of-stdoptional)
761+
762+
----------------------------------------------------------
763+
</details>
764+
724765
## PS
725766

726767
### Most of the code snippets are validated automatically

0 commit comments

Comments
 (0)