logs and handling sql exceptions