Difference between revisions of "Intermediate C++ Game Programming Tutorial 22"
From Chilipedia
(→Video Timestamp Index) |
(→Video Timestamp Index) |
||
Line 44: | Line 44: | ||
*:- <code>std::logic_error</code>: due to faulty logic within the program | *:- <code>std::logic_error</code>: due to faulty logic within the program | ||
*:- <code>std::runtime_error</code>: due to events beyond the scope of the program (such as file access errors) | *:- <code>std::runtime_error</code>: due to events beyond the scope of the program (such as file access errors) | ||
− | * You can create your own error classes that inherit from the existing one for customized and finer-grained error handling | + | * The inherentance hierarchy of <code>std::exception</code> is very useful [https://youtu.be/DMdyz0lrFBI?t=10m49s 10:49] |
+ | ** The polymorphism lets you choose the level of detail in error handling | ||
+ | ** You can create your own error classes that inherit from the existing one for customized and finer-grained error handling | ||
+ | |||
* WORK-IN-PROGRESS | * WORK-IN-PROGRESS | ||
</div> | </div> |
Revision as of 05:02, 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
-
std::exception
and its derivatives - Polymorphism in exception handling
-
catch(...)
- Throw by value, catch by
const
reference - Exceptions and destructors
-
noexcept
and move constuctors vs. standard containers
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- In this case, you don't get any exception object or value that you can output
- Rethrowing still works
- Good practice: only throw exception objects that inherit from the
std::exception
class 9:51- STL offers a range of pre-defined exception objects, with two basic general types:
- -
std::logic_error
: due to faulty logic within the program - -
std::runtime_error
: due to events beyond the scope of the program (such as file access errors)
- The inherentance hierarchy of
std::exception
is very useful 10:49- The polymorphism lets you choose the level of detail in error handling
- You can create your own error classes that inherit from the existing one for customized and finer-grained error handling
- WORK-IN-PROGRESS
Extra Discussion
I had an interesting exchange with a viewer, and made a bit of a writeup here: essay time.