Handles exception when writing to database.

Refs #91