Fix exception when exit