Adam Bien's Weblog

Exceptions Are Objects

Exceptions are objects and should be treated as such. Organizing exceptions in an exception(s) package is problematic. Consequently you would also have to create packages for classes, interfaces, beans etc.

Usually you are not searching for classes, interfaces or exceptions during the development cycle, rather than for functionality first. It is a better idea to organize the code after domain responsibilities and not obvious nature. Also it easily possible to find exceptions with any modern IDE regardless of their location: all exceptions have to inherit from java.lang.Exception

It is also a bad idea to use util packages as kitchen sink.

See you at Java EE Workshops at MUC Airport, particularly Effective JavaEE and JavaEE Architectures!


NEW workshop: Java EE 7 and Java 8, January 27th, 2015, Airport Munich

A book about rethinking Java EE Patterns

Comments:

Agreed. The same goes for any Java type. I saw someone recently created XEnum class in our project, where X is the type of the entity, that enum represents.

Posted by Anton on April 25, 2013 at 11:14 PM CEST #

It is however good to organize Exceptions AND Interfaces together in an exported package seperate from the implementation (if you do OSGi or other Service technologies).

Posted by Bernd on May 01, 2013 at 03:48 AM CEST #

Post a Comment:
  • HTML Syntax: NOT allowed
realworldpatterns.com
...the last 150 posts
...the last 10 comments
License