Fixed #524. Exception formatting callback and handle SQLa IntegrityErrors even in debug mode