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 在表現形式上沒有區別, 代表出錯邏輯不同。 We should document the exception and don't catch or throw "Exception". Exception can be pass to high level throw transmit(轉義), 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()).如果有狀態相關的方法, 最好有測試狀態相關的代碼。 User common exception like IllegalArgumentException, IllegalStateException, NullPointerException...

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


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          <2025年7月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          導航

          統計

          常用鏈接

          留言簿(3)

          隨筆檔案

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 鹿邑县| 青神县| 虎林市| 饶河县| 景宁| 丹凤县| 武穴市| 华亭县| 安新县| 牡丹江市| 兰考县| 平山县| 济阳县| 阜阳市| 静安区| 南开区| 遵化市| 疏勒县| 藁城市| 昭觉县| 博兴县| 金寨县| 兖州市| 涿鹿县| 武乡县| 富源县| 慈溪市| 德令哈市| 长葛市| 澄城县| 河池市| 棋牌| 文成县| 历史| 禹城市| 海原县| 舞阳县| 宝丰县| 武陟县| 郁南县| 东方市|