:::: MENU ::::

A Defect Exception

Occasionally one comes across a idea that is just brilliant.

How often have you been writing a bit of code, and got to a point where you think “gee, if the program ever gets into this state, then something is really wrong”. Throwing an exception seems appropriate, but what kind of exception to throw?

Enter the following sage advise from Steve Freeman and Nat Pryce in their great book “Growing Object Orientated Software Guided by Tests”:

Growing Object Orientated Software Guided By Tests - pg165

Growing Object Orientated Software Guided By Tests - pg165

A DefectException(). What a simple but brilliant idea!

Thanks guys


One Comment

  • Reply Greg Lucas |

    David, you’re right. Sometimes it’s the simplest ideas that are the most brilliant. I was beginning to think you’d given up on your blog. Which reminds me, I must start working on mine again :-)

So, what do you think ?