Call exit function when an exception is thrown