handle exception to avoid inconsistent state