exit function when an error occured