Move checking for error results into exit_err(), out of conditionals in the remaining code.