SAX: Exception Handling

David Brownell David.Brownell at Eng.Sun.COM
Mon May 4 17:57:45 BST 1998


> >    throws java.lang.Exception
> >  {
> >    [..]
> >  }
> > 
> > The Java compiler will not help me discover which constructors or
> > methods invoked in the body can throw exceptions that I have not yet
> > considered.
> 
> Right, so don't do that.  Declaring an *interface* as throws
> java.lang.Exception does not constrain an *implementation* of that
> interface to be declared as throws java.lang.Exception.  It can be
> declared to throw the appropriate subclass of java.lang.Exception.

But then since application programmers write to interfaces, not
implementations, then application programmers would have all those
nasty problems with getting handed random exceptions.

A primary intent of exception declarations is to constrain the
kinds of errors that a substystem (e.g. parser) reports, so that
its clients have a clean "contract" and know exactly the kinds of
"expected faults" they have to deal with.

Clauses like "throws Exception" are basically counter to the core
philosophy of exceptions in Java.

- Dave


xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev at ic.ac.uk
Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/
To (un)subscribe, mailto:majordomo at ic.ac.uk the following message;
(un)subscribe xml-dev
To subscribe to the digests, mailto:majordomo at ic.ac.uk the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa at ic.ac.uk)




More information about the Xml-dev mailing list