Throw exception with custom error message if provided.

Fixes #7. @ianlivingstone