I have never seen someone use an inner-class as an Exception. I would
advise against it.
Usually, inner classes are used only (or mostly) within the outer
class, or when directly communicating to the outer class. I know there
are a couple of exceptions, but unless you have an overwhelming reason
to make it an inner class, make it a top level class.
Daniel Pitts napisał(a):
>> Daniel Pitts napisał(a):
>>> You could do this, however, those exceptions seem like they are
[quoted text clipped - 8 lines]
> I have never seen someone use an inner-class as an Exception. I would
> advise against it.
Well, I have never seen that either, thats is why I am confused :)
> Usually, inner classes are used only (or mostly) within the outer
> class, or when directly communicating to the outer class.
Do not forget I am talking about static inner classes, they are usable
without outer class.
I think the problem with Java is that you cannot expose only some
classes outside of your library which makes life hard when using
libraries (there are much to many public classes (there is nothing
between package scope and public scope). That is why I am trying to
avoid using top level classes whenever I can to make API more readable.
Declaring Exception for particular interface inside that interface was
what I though a good idea, but maybe I am wrong :/
> I know there
> are a couple of exceptions, but unless you have an overwhelming reason
> to make it an inner class, make it a top level class.
Yes, I do not have "overwhelming reason" :)
Thanks, bye!
Ed Kirwan - 19 Dec 2006 08:29 GMT
> I think the problem with Java is that you cannot expose only some
> classes outside of your library which makes life hard when using
[quoted text clipped - 3 lines]
> Declaring Exception for particular interface inside that interface was
> what I though a good idea, but maybe I am wrong :/
Kudos for the attempt. I'm in the school of
one-public-concrete-class-per-package myself. A die-hard Facader. Have
you checked the Sun-defined Java exceptions? If your hierarchy's not too
deep (or the distance your throwing your exception not that far) then a
Sun-defined exception may offer sufficient distinctiveness (as our Borg
friends might say).
You may, furthermore, find this of interest:
http://groups.google.se/group/comp.lang.java.programmer/browse_frm/thread/be00fa
992f76aa79/8e555b216fa7fc33?lnk=gst&q=gilad&rnum=1&hl=sv#8e555b216fa7fc33
.ed

Signature
www.EdmundKirwan.com - Home of The Fractal Class Composition.
Download Fractality, free Java code analyzer:
www.EdmundKirwan.com/servlet/fractal/frac-page130.html