emit error events instead of throwing where possible

refactored into dispatchError(err, callback), which
calls the callback if it's set, otherwise emits the error
on the db object

This closes #48