[2469] in java-interest
Re: throws declataration in Java/beta
daemon@ATHENA.MIT.EDU (David Smyth)
Tue Oct 3 01:30:10 1995
Date: Mon, 2 Oct 95 09:00:11 PDT
From: dsmyth@mpfcmd1.jpl.nasa.gov (David Smyth)
To: java-interest@java.sun.com
(sorry, I don't have all the previous authors)
> > >Only forseen exceptions are generally required to be declared (and
> > >therefore need to be caught or explicitly passed on). Exceptions which
> > >are subclasses of RuntimeException or Error - which are not generally
> > >part of the API of a given method - don't have to be declared.
Does this mean that all exceptions generated by subclasses should be derived
from RuntimeException or Error?
> > >Exceptions such as IOException, which are part of the natural working
> > >domain of many methods, must be declared where they can occur so that
> > >callers of that method are aware that the indicated exception is a
> > >possible result of calling the method.
This seems like splitting hairs. Why isn't an IOException a RuntimeException
or an Error?
> > It seems to me that this reasoning has a flaw. It assumes that the base
> > class designer can forsee all possible algorithms needed by all possible
> > subclasses, and include the necessary exception declarations to cover
> > them.
I also feel this way. The "subclasses of RuntimeException or Error" seems to
eliminate this concern, but only because it means that in fact any subclass
can throw "any" exception, that it invents anyway.
> Can you give a concrete example? If a subclasser wants to throw a new kind
> of exception, then he is most likely trying to fit a round peg into a
> square hole...
OK: ScrollableItemNotFound exception for a derived button to be used in a
floating "remote control" or palette, which causes the top-most window's
scrollable item to scroll downwards.
It seems that the most useful concept behind exceptions is not that there is
a fixed set, but that they can be used to handle rare failures, so the code
is more readable: the "straight" code deals with the nominal case, and the
"catch" code deals with all sorts of possible exceptions.
______________________________________________________________________
| David E. Smyth David.E.Smyth@jpl.nasa.gov |_
| Mars Pathfinder Flight Software -- Object-Oriented Software for Mars | |
|______________________________________________________________________| |
| "It isn't exactly rocket science... well, I guess maybe it is..." | |
|______________________________________________________________________| |
|______________________________________________________________________|
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com