Difference between revisions of "Intermediate C++ Game Programming Tutorial 22"
From Chilipedia
(→Video Timestamp Index) |
(→Video Timestamp Index) |
||
Line 75: | Line 75: | ||
** You can enable move operations in these cases by making the move constructor <code>noexcept</code>, which explicitly tells the compiler that there will be no exception thrown | ** You can enable move operations in these cases by making the move constructor <code>noexcept</code>, which explicitly tells the compiler that there will be no exception thrown | ||
** Be mindful of when you mark your functions noexcept. You basically enter into a contract with whomever is using your code that the function will never throw exceptions. If you would ever want to change this, you risk nasty errors because the codebase may rely on your function being <code>noexcept</code>. | ** Be mindful of when you mark your functions noexcept. You basically enter into a contract with whomever is using your code that the function will never throw exceptions. If you would ever want to change this, you risk nasty errors because the codebase may rely on your function being <code>noexcept</code>. | ||
− | </ | + | </div> |
* Best practices [https://youtu.be/DMdyz0lrFBI?t=21m56s 21:56] | * Best practices [https://youtu.be/DMdyz0lrFBI?t=21m56s 21:56] | ||
<div class="mw-collapsible-content"> | <div class="mw-collapsible-content"> |
Revision as of 06:48, 24 November 2019
In this video we learn how to use C++ exceptions to take our error handling to the next level. There is a lot of fear and ignorance surrounding exceptions among "C++ Programmers", and Chili's goal here is to elevate you guys above the shit-tier level to coders who can actually use this feature to its full extent. The second part of this tutorial will give concrete, practical examples of using exceptions in an actual game scenario.
Contents
[hide]Topics Covered
- Basic exception
try
ingthrow
ing andcatch
ing - Exceptions 'bubbling up'
- Rethrowing with
throw
-
catch(...)
-
std::exception
and its derivatives - Polymorphism in exception handling
- Exceptions and destructors
-
noexcept
and move constuctors vs. standard containers - Throw by value, catch by
const
reference
Video Timestamp Index
[Expand]
- Intro: exceptions are the main way of handling errors in C++ 0:10
- Comparing error handling with and without exceptions 1:40
- Example code to demonstrate
try
,throw
,catch
of astd::runtime_error("...")
3:53
- Use
catch(...)
to catch any uncaught excepions 8:55
- Good practice: only throw exception objects that inherit from the
std::exception
class 9:51
-
std::exception
and its derivatives 10:49
- Unwinding the stack: what happens to objects when throwing out of scope 13:39
- Exceptions and destructors 17:17
- Move semantics and containers 18:34
- Best practices 21:56
Extra Discussion
I had an interesting exchange with a viewer, and made a bit of a writeup here: essay time.