Author image

Exception Class Hierarchies in C++


How to use exceptions, manage error codes in your C++ programs? That is the question of the day.

Luckily c++ exceptions are pretty standard in their programming. The strategy is to create a base exception class with a name of your choosing (KeyException was mine) and then you can create subclass exception classes, nested in the various principal classes of your codebase. For example, in a game engine project you can create GraphicsException, WindowException, KeyboardException all inherit from KeyException and override the getType and what() functions to provide meaningful unambiguous errors.

Let's start with a tiny C++ exception primer -reminder- though before you get your hands on the code.

You handle exceptions using a try block. 

1