C++: Exception for Unimplemented Code

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) {}
};

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>