check exception before exit