A Java library that I’d like to see that I can’t seem to find is an exception library. Now, your first reaction might be something like, that’s silly because an exception doesn’t make sense outside of the context it’s used in. But, what got me thinking about this assumption was the general thoughtlessness and messiness you see in exception hierarchies of applications. I think this is generally because exceptions have minimal dependencies. This makes them easy to add and individually low impact so programmers add them willy-nilly with little thought. But like grains of sand in an engine, they can add up and becomes become a major irritant. My first clue that this is not the way it has to be is from the Spring framework’s database exception hierarchy. Spring’s exceptions actually get a lot of treatment and it’s obvious that they actually thought this one out! Also, in Joshual Bloch’s Effective Java Item 42 states “Favor use of standard exceptions”. So putting these together, you get: exceptions should be actually designed (rather than added ad-hoc) and they should be general.

This of course leads to the idea of using an exception library. The JDK has a few general exceptions that are quite useful but they do not cover that many cases. Spring has a good general database hierarchy but not any for other areas. Unfortunately, in my search, the exception library aisle (going back to shopping) is empty. Maybe I’m not looking hard enough?