In the previous part of the error handling series I’ve talked about assertions and wrote a debug assert library that provides flexible assertions.
Assertions are a useful tool to check preconditions of functions - but proper type design can prevent situations where assertions are needed. C++ has a great type system, let’s use it to our advantage.
At the recent CppCon Ben Deane gave a - as far as I’ve heard - great talk about type design. I sadly didn’t attend the conference and his video isn’t released yet but according to the slides there is some overlapping between his talk and what I’m going to say. But because I’ve planned this posts for weeks and even made the entire series just for it I decided to post it anyway. After all: some things cannot be said often enough.
» read more »
Also I’m going to focus explicitly about type design for error handling, while his talk seems to be more generic.