This is review of the 7th chapter from the book-”Clean Code: A Handbook of Agile Software Craftsmanship” by Robert C. Martin.
Exceptions are a way of life . You can hide but not escape.
But you can handle the possibility of an error in way so that you can make your life easier.
Use Exceptions rather than Error Codes. Using error codes intermingles your normal flow with the error flow and you are forced to handle the error immediately. With Exceptions- you can procrastinate the handling to a later point in the flow and also keeps your normal flow and error flow in separate drawers- neatly.
When catching exceptions- you have the opportunity to capture more information about the error. e.g. you can capture the offending SQL or maybe the arguments of the method which could be responsible for the error.
On classifications of exceptions- think about the caller. Is the caller going to handle the two types of error differently or the same way? If it is going to handle in a different way- you then may need two different exceptions- else one would suffice.
For review of other chapters- please see this post.






March 19th, 2009 at 4:31 pm
[...] Chapter 4: Comments Chapter 5: Formatting Chapter 6: Objects and Data Structures Chapter 7: Error Handling Chapter 8: Boundaries Chapter 9: Unit Tests Chapter 10: Classes Chapter 11: Systems Chapter 12: [...]