commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Martin Cooper" <mart...@apache.org>
Subject Re: [io] Inner class exception
Date Tue, 09 Jan 2007 15:34:03 GMT
On 1/8/07, Henri Yandell <flamefew@gmail.com> wrote:
>
> On 1/8/07, Martin Cooper <martinc@apache.org> wrote:
> > On 1/8/07, Henri Yandell <flamefew@gmail.com> wrote:
> > >
> > > On 1/8/07, Stephen Colebourne <scolebourne@btopenworld.com> wrote:
> > > > Martin Cooper wrote:
> > > > > Could you say more about this, please? I happen to disagree on
> > > > > exceptions as
> > > > > inner classes being a bad idea; FileUpload has done this for
> years,
> > > without
> > > > > any problems. But I'm always interested in hearing new
> perspectives...
> > > >
> > > > I guess its stylistic, and therefore subjective. But I see an
> exception
> > > > as a critical system object, and not one that should be relegated to
> > > > inner class status.
> > >
> > > +1
> > >
> > > } catch( DirectoryWalker.CancellationException ce) {
> > > ...
> > > }
> > >
> > > feels weak to me.
> >
> >
> > Weak why?
>
> Because I'm not used to it I suspect. It's not a common idiom so not
> something my eyes naturally parse, and if I was writing the code I
> suspect it would take a bit longer to write. Not char-wise, I mean in
> terms of realising what I was meant to catch.
>
> Stephen mentioned the javadoc. Looking at that, I doubt I'd be
> catching DirectoryWalker.CancellationException anyway - the method
> that it is thrown from throws IOException. The
> DirectoryWalker.CancellationException isn't in its contract, except as
> an argument passed in.
>
> The examples in the Javadoc look bad btw. They refer to CancelException
> and not
> DirectoryWalker.CancellationException.
>
> > To me, it makes the code very explicit about what is being
> > cancelled. It also, by the way, allows for other classes to have a
> > CancellationException without having to make up some other name, because
> the
> > enclosing class scopes the exception class name and allows its reuse in
> > other classes. It seems like an eminently suitable way of naming /
> scoping
> > tightly coupled classes such as we see with these types of exceptions.
>
> Good arguments - though they just make me think in terms of a more
> specific class name - "WalkCancelledException".


Probably because you're not used to the inner class way. ;-)

This helps with naming, but without the scoping, you're left with the
Javadocs as the only way to specify that the exception is intended to be
used only within the DirectoryWalker class. Of course, a public static inner
class can be used elsewhere as well, but the relationship with the enclosing
class makes a clear statement of intent.

We can agree to disagree, though - I was mostly just interested in what the
arguments are against using inner classes, given that I see very clear and
meaningful reasons for using them.

--
Martin Cooper


Hen
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message