Difference between revisions of "Intermediate C++ Game Programming Tutorial 22"

From Chilipedia
Jump to: navigation, search
(Video Timestamp Index)
(Video Timestamp Index)
Line 41: Line 41:
 
** Rethrowing still works
 
** Rethrowing still works
 
* Good practice: only throw exception objects that inherit from the <code>std::exception</code> class [https://youtu.be/DMdyz0lrFBI?t=9m51s 9:51]
 
* Good practice: only throw exception objects that inherit from the <code>std::exception</code> class [https://youtu.be/DMdyz0lrFBI?t=9m51s 9:51]
** STL offers a range of pre-defined exception objects, the most important being <code>std::logic_error</code> and <code>std::runtime_error</code>
+
** STL offers a range of pre-defined exception objects, with two basic general types: <code>std::logic_error</code> and <code>std::runtime_error</code>
 
* WORK-IN-PROGRESS
 
* WORK-IN-PROGRESS
 
</div>
 
</div>

Revision as of 04:55, 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.

Topics Covered

  • Basic exception trying throwing and catching
  • 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

Tutorial 22 Part 1

[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 a std::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 and std::runtime_error
  • WORK-IN-PROGRESS

Tutorial 22 Part 2

Extra Discussion

I had an interesting exchange with a viewer, and made a bit of a writeup here: essay time.

Source Code

See also