Sunday, June 29, 2014

Handling Exceptions in C++ Testing

More C++ content.  Maybe I need to rename this blog.  

The other day I was writing some throwaway code, and I ran into a situation I've seen before:  some of my test code was (correctly) throwing an exception.  My immediate reaction was the wrap it in a try block.  But that only led to more try blocks, and some pretty smelly code.  So I whipped up a  template that would take a lambda as a argument, and would crash the program if the lambda didn't emit an exception when called.