views:

92

answers:

2

I prefer to have the "rc" error-code return style of error management. I agree that this presents challenges that are better served by throw-catch, however, I still feel that I am not designing and implementing in a style that is clean and maintainable. So, I am looking for a good book that discusses the pattern and is not simply a reference book.

A bibliography of references would be fine too ...

An excerpt from the answer below, "Practices of an Agile Programmer", that I found especially striking:

**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.
A: 

I'm not aware of any book dealing specifically with best practices of exception throwing/usage. It may be too specific a topic to warrant an entire book. Also, best practices are likely to be vary significantly for each programming language (C++ vs. Java), as well as programming contexts within a language (C# winforms vs. C# asp.net).

I suspect your best bet is to google it; you'll likely find some blog posts that address the topic (hopefully, the best/most-respected ones will be near to top of google results).

mikemanne
Thanks moikemanne - actually, I posted the question after weeks of surfing while dealing with the monster. I totally agree with your assessment about the specificity and that is likely the reason for my search with the community.
mobibob
+2  A: 

I have not found a book dedicated to exception handling, but there are some which deal with this topic at the length of a section or chapter.

As a primer and for a language agnostic approach see [Martin, Ch. 7]. [McConnel, Ch. 8.4] also deals with exception handling on a very general basis. For addtionally good advices for the use of exceptions see [Subramaniam, Hunt, Ch. 36, 37]. I also found [Richter, Ch. 20] very useful although it is specific to .NET and C#. Nevertheless some sections are applicable to other languages, too.

Recommendation: As an alternative approach to throwing exceptions and error-code return style of programming, do some research on the "Special Case Pattern" or "Null Object Pattern" in the WWW.

  • [Martin] Martin, C. R. (2008). Clean Code: A Handbook of Agile Software Craftsmanship. Prentice Hall International.
  • [McConnel] McConnel, S. (2004). Code Complete.
  • [Subramaniam, Hunt] Subramaniam, V., & Hunt, A. (2006). Practices of an Agile Developer. Pragmatic Programmers.
  • [Richter] Richter, J. (2010). CLR via C#. Microsoft Press.
Theo Lenndorff
I have only checked the citation "Practices of an Agile Developer" and came away with some excellent guidelines along with a discussion with the scenario that is plaguing me. Therefore, I think this is the starting point that I was looking for and awarded it to be the answer. Over time I expect this to get further refined and validated. - thanks Theo.
mobibob
You should really check out [Martin], too. It describes the flaws of the return code style and contrast it with exception handling. [Martin] uses code examples to illustrate this very impressively. [Subramaniam, Hunt] is more on the level of practices than code.
Theo Lenndorff