exit when an error occurs