Catch error when checking values on database write