handle exception correctly