Exception package

I've been working with custom exception classes, that is classes which extend from java.lang.Exception but have slight additional functionality and have more descriptive names. I've been keeping them inside whatever package seemed appropriate given the nature of the exception. So for example my ValidationException is kept in the model package and the DatabaseException is kept in the persistance package. But I was wondering if it is standard, desirable, or better design to create an entirely separate package specifically for exceptions, like an "error" package or maybe use my "util' package and keep them all in one place. Or does it matter. Maybe just personal preference.

Thanks for any feedback.

[720 byte] By [nantucketa] at [2007-10-2 15:53:57]
# 1

The convention--which you can see by examining java.io, javal.sql, java.util, and any number of 3rd party packages--is that the exceptions go in the package to whose functionality they are related. This makes sense to me. I think a FileNotFoundException is much better associated with File and the other classes in java.io than with, say, DateFormatException if you stuffed all your exceptions in one package.

Now, if you're trying to create a new model for error handling that can cut across all packages, and you're approaching it from an AOP perspective, then there might be good reason to lump some bunch of exceptions together, due to the relationships among them in your AOP world. That's just speculation though, as I've never done any real AOP myself and have only even read just a little bit about it.

jverda at 2007-7-13 16:07:23 > top of Java-index,Other Topics,Patterns & OO Design...
# 2

Thanks for your response jverd. Yeah I didn't think about looking at the java packages themselves before posting, good idea. And that may be why I've adopted the practice I had been using, placing them in the packages based upon their definition and functionality. But I'm refactoring some code now and second guessed myself. No, I'm not working on Aspect oriented stuff right now. I've not looked too deeply into what that is exactly.

Thanks again.

nantucketa at 2007-7-13 16:07:23 > top of Java-index,Other Topics,Patterns & OO Design...
# 3
Caveat: it isn't always true that because Sun did it a certain way, then that's the best way to do it and that's the way you should do it. But it is very often true, and in this case I agree with jverd that in the absence of any special design features, you should do it the way Sun did
DrClapa at 2007-7-13 16:07:23 > top of Java-index,Other Topics,Patterns & OO Design...
# 4

> Caveat: it isn't always true that because Sun did it

> a certain way, then that's the best way to do it and

> that's the way you should do it.

Right. I didn't mean to imply that it was. Only to show that we have abundant examples that that's the way it's coventionally done.

jverda at 2007-7-13 16:07:23 > top of Java-index,Other Topics,Patterns & OO Design...
# 5
> Right. I didn't mean to imply that it was. Only to> show that we have abundant examples that that's the> way it's coventionally done.What a gathering of earth mothers do in their private moments together is nobody's business but their own.
jverda at 2007-7-13 16:07:23 > top of Java-index,Other Topics,Patterns & OO Design...
# 6

> > Right. I didn't mean to imply that it was. Only to

> > show that we have abundant examples that that's

> the

> > way it's coventionally done.

>

> What a gathering of earth mothers do in their private

> moments together is nobody's business but their own.

So I should turn off the hidden video camera?

jverda at 2007-7-13 16:07:23 > top of Java-index,Other Topics,Patterns & OO Design...
# 7

> > > Right. I didn't mean to imply that it was. Only

> to

> > > show that we have abundant examples that that's

> > the

> > > way it's coventionally done.

> >

> > What a gathering of earth mothers do in their

> private

> > moments together is nobody's business but their

> own.

>

> So I should turn off the hidden video camera?

Probably.

I can see it now....

Download your copy of "Covens Gone Wild!" from the JWord today.

jverda at 2007-7-13 16:07:23 > top of Java-index,Other Topics,Patterns & OO Design...