When an exception is thrown, exit appropriately