- Create an exit function for safe exit at error