You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -45,10 +45,6 @@ So get a coffee and buckle up! There is a lot to cover and quite some nuance in
45
45
46
46
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?
47
47
48
-
<!-- Add a video from shreck?
49
-
Link: https://www.youtube.com/watch?v=Waa9UqVP4KI
50
-
-->
51
-
52
48
# Disclaimer
53
49
54
50
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
63
59
64
60
Now, back to error handling. -->
65
61
66
-
<!-- TODO: Film the camera that films me, slowly zooming in. -->
67
-
68
62
# What Do We Mean by “Error”?
69
63
70
64
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
227
221
Reference numbers: 42 49 23
228
222
Player numbers: 10 40 24
229
223
Please enter number to change: 40
230
-
Please provide a a new value: 49
224
+
Please provide a new value: 50
231
225
Budget: 2
232
226
Reference numbers: 50 49 23
233
227
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
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.
345
339
346
340
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.
347
341
@@ -428,8 +422,6 @@ c++ -std=c++17 -DNDEBUG -o comparison_game comparison_game.cpp
428
422
429
423
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!
430
424
431
-
<!-- Get the UB kick assert's ass, and me pushing the UB away -->
-[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-)
-[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)
0 commit comments