Effective Java - Exception

          Exception's principle: Only have exceptions happened, use it, do not to use it control work flow, for three reasons: 1.when JVM optimize some common operation(e.g. for circle), when we use exception to instead it, JVM won't do optimize. 2. None of JVM used to optimize exception now. 3. Create and throw exception will take some JVM resources. 4. Hard to understand bussiness logic(my understanding). There is three kinds of Exception: Exception, RuntimeException, Error. Exception: Checked exception. RuntimeException: program error. Error: For environment error, JVM will handle it or define it. Error and RuntimeException 在表現(xiàn)形式上沒(méi)有區(qū)別, 代表出錯(cuò)邏輯不同。 We should document the exception and don't catch or throw "Exception". Exception can be pass to high level throw transmit(轉(zhuǎn)義), it means we can transmate one kind exception(JDK exception) to another kind of exception(Bussiness exception). If we want to store the low level exception, can pass low level exception information throw "Exception chain", before JDK1.4, we should implemnts it by ourselves, we define a Throw field in our custom exception, and store the low level exception as its part, After JDK1.4, we can pass low level exception throw Construct. Two way to instead of exception: Return a value, get a "testing method"(Iterator.hasnext()).如果有狀態(tài)相關(guān)的方法, 最好有測(cè)試狀態(tài)相關(guān)的代碼。 User common exception like IllegalArgumentException, IllegalStateException, NullPointerException...

          posted on 2006-09-04 09:00 Sheldon Sun 閱讀(284) 評(píng)論(0)  編輯  收藏


          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          <2025年7月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿(3)

          隨筆檔案

          文章檔案

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 新丰县| 高要市| 宝丰县| 凉山| 晋宁县| 门头沟区| 高邑县| 微山县| 葵青区| 德清县| 沐川县| 长寿区| 白水县| 温泉县| 那曲县| 大同县| 竹溪县| 临安市| 浑源县| 和硕县| 蓝山县| 万年县| 陈巴尔虎旗| 恭城| 咸宁市| 海宁市| 城固县| 江阴市| 沙雅县| 临沂市| 乌兰县| 儋州市| 台北市| 祁阳县| 葫芦岛市| 增城市| 吉首市| 四会市| 汉川市| 汉源县| 塔城市|