我更喜欢使用“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