There should be a standard hierarchy of Exceptions based on how users are expected to handle them, independent of the classes and packages that happen to throw them.
All Exceptions should implement one of two interfaces:
The failure of the Java language (and in others I imagine) is that Exceptions are tied closely to classes and packages.
(ShamelessPlug?: In CommonLisp, exceptions are almost entirely decoupled from both classes and packages.)
[Original text by DaveTauzell (10/12/2001). Edited heavily by JeffGrigg on 10/15/2001.]
The Java language currently contains java.lang.Error and java.lang.Exception, which are similar in some respects to what is described above.
(Perhaps we need a better separation between "business" and "technical" exceptions within java.lang.Exception.)
Why not just create your own Business Exception class, and derive all your other "business" exceptions from that? Why should such a thing be defined by the Java language/runtime (or whatever other programming language you are using)?
Because you still have to deal with lots of Java exceptions under java.lang.Exception, and they're not in a very useful hierarchy, judging from the perspective of the application I happen to be writing.
(Personally, I think this page is wishful thinking, as there really isn't any way a framework developer can tell, in advance, how their users will view exceptions on the business -vs- system boundary. And the line will move from time to time, even within a single application system. -- JeffGrigg)
Java exception hierarchy:
http://www.ebone.at/books/programmers/sonstiges/oreillybookself/java/langref/ch09_04.htmAlso: Java has a MessyExceptionHierarchy.
The problem is that one person's business rule is another person's system rule. E.g. my XML parsing library throws an exception because the XML syntax is invalid. From my point of view, a business rule was violated (invalid input). You might see this quite differently, especially if the XML file wasn't directly provided by the user but is some configuration file of which the user knows little.
I agree. The distinction between "business" and "system" doesn't really capture the different kinds of errors. I see three categories:
See also CheckedExceptionsAreOfDubiousValue