我更喜歡使用「rc」錯誤代碼返回錯誤管理風格。我同意這會帶來更好的投擲挑戰,但是,我仍然覺得我並不是以一種乾淨和可維護的風格進行設計和實施。所以,我正在尋找一本討論這種模式的好書,而不僅僅是一本參考書。有人可以引用一個很好的例外編程參考嗎?
引用的參考文獻就太細...
從下面的答案的摘錄,「敏捷編程的實踐」,我發現特別引人注目:
**Keeping Your Balance**
• Determining who is responsible for handling an exception is part of design.
• Not all situations are exceptional.
• Report an exception that has meaning in the context of this code. A NullPointerException is pretty but just as useless as the null object described earlier.
• If the code writes a running debug log, issue a log message when an exception is caught or thrown; this will make tracking them down much easier.
• Checked exceptions can be onerous to work with. No one wants to call a method that throws thirty-one different checked exceptions. That’s a design error: fix it, don’t patch over it.
• Propagate what you can’t handle.
我只檢查了引用「敏捷開發人員的實踐」,並帶來了一些極好的指導方針以及與困擾着我的場景的討論。因此,我認爲這是我尋找的起點,並將其作爲答案。隨着時間的推移,我預計這將得到進一步完善和驗證。 - 謝謝Theo。 – mobibob 2010-10-04 20:20:13
你也應該看看[Martin]。它描述了返回代碼樣式的缺陷,並將其與異常處理進行對比。 [Martin]使用代碼示例非常令人印象深刻地說明這一點。 [Subramaniam,Hunt]在實踐層面比代碼更多。 – 2010-10-04 21:28:55