Added missing error handling.

Fixes #43.
Merge pull request #44 from rhyolight/bugfix

Added missing error handling.