Exit function on exception