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

From Chilipedia
Jump to: navigation, search
(Video Timestamp Index)
(Video Timestamp Index)
 
(24 intermediate revisions by the same user not shown)
Line 13: Line 13:
  
 
== Video Timestamp Index ==
 
== Video Timestamp Index ==
* [https://youtu.be/DMdyz0lrFBI Tutorial 22 Part 1]
+
[https://youtu.be/DMdyz0lrFBI Tutorial 22 Part 1]
* [https://youtu.be/_6G5yDgoWiA Tutorial 22 Part 2]
+
<div class="mw-collapsible mw-collapsed"><br />
 +
* Intro: exceptions are the main way of handling errors in C++ [https://youtu.be/DMdyz0lrFBI?t=0m10s 0:10]
 +
<div class="mw-collapsible-content">
 +
** Examples of its usage in the Framework, a good practice for working with any API
 +
** Everytime a Direct 3D Function is called, the return value is checked for error codes and handled
 +
</div>
 +
* Comparing error handling with and without exceptions [https://youtu.be/DMdyz0lrFBI?t=1m40s 1:40]
 +
<div class="mw-collapsible-content">
 +
** Conventional error handling requires checking function return errors for every function throughout the entire hierarchy of the code base
 +
** With exceptioins the advantages are:
 +
*:- you can catch an error anywhere in the code base (they "bubble up", or propagate up to a higher level function)
 +
*:- you can seperate your normal logic (code) from your error handling.
 +
*:- if you don't handle the error at some point, your program will be halted
 +
</div>
 +
* Example code to demonstrate <code>try</code>, <code>throw</code>, <code>catch</code> of a <code>std::runtime_error("...")</code> [https://youtu.be/DMdyz0lrFBI?t=3m53s 3:53]
 +
<div class="mw-collapsible-content">
 +
** The <code>catch</code> function is only executed if an exception has been thrown
 +
** Illustration of how exceptions can propagate out of functions
 +
** You can decide the level at which you want to catch an exception [https://youtu.be/DMdyz0lrFBI?t=6m04s 6:04]
 +
** Catch and rethrow [https://youtu.be/DMdyz0lrFBI?t=6m40s 6:40]
 +
** You can <code>throw</code> anything you want: an object, an Integer, string, pointer, etc.
 +
** You van overload the <code>catch</code> functions based on the type of information thrown
 +
</div>
 +
* Use <code>catch(...)</code> to catch any uncaught excepions [https://youtu.be/DMdyz0lrFBI?t=8m55s 8:55]
 +
* WORK-IN-PROGRESS
 +
</div>
 +
[https://youtu.be/_6G5yDgoWiA Tutorial 22 Part 2]
  
 
== Extra Discussion ==
 
== Extra Discussion ==

Latest revision as of 05:28, 11 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


  • Intro: exceptions are the main way of handling errors in C++ 0:10
    • Examples of its usage in the Framework, a good practice for working with any API
    • Everytime a Direct 3D Function is called, the return value is checked for error codes and handled
  • Comparing error handling with and without exceptions 1:40
    • Conventional error handling requires checking function return errors for every function throughout the entire hierarchy of the code base
    • With exceptioins the advantages are:
    - you can catch an error anywhere in the code base (they "bubble up", or propagate up to a higher level function)
    - you can seperate your normal logic (code) from your error handling.
    - if you don't handle the error at some point, your program will be halted
  • Example code to demonstrate try, throw, catch of a std::runtime_error("...") 3:53
    • The catch function is only executed if an exception has been thrown
    • Illustration of how exceptions can propagate out of functions
    • You can decide the level at which you want to catch an exception 6:04
    • Catch and rethrow 6:40
    • You can throw anything you want: an object, an Integer, string, pointer, etc.
    • You van overload the catch functions based on the type of information thrown
  • Use catch(...) to catch any uncaught excepions 8:55
  • 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