C++: Exception for Unimplemented Code

by Ben

I often like to derive an unimpl_error class (or something like it) so that as I’m fleshing out various parts of a piece of software, I can mark something as unimplemented by throwing an exception. I suppose a // TODO comment would serve the purpose, but for some reason, I like the exception idea. That way, if I forget that I didn’t write some function, if I try to call it I’ll get my reminder :-)

Anyway, I do this often enough that I thought it deserved to go in my collection of design patterns and idioms.


#include

class unimpl_error : public logic_error
{
public:
unimpl_error(std::string &msg) throw()
: std::logic_error(msg) {}
};