Java Reference
In-Depth Information
If a method declaration is multiply inheritedthat is, it exists in more than
one inherited interface, or in both an inherited interface and a super-
classthen the tHRows clause of that method must satisfy all the inherited
tHRows clauses. As we discussed in " Inheriting, Overriding, and Overload-
ing Methods " on page 125 , the real issue in such multiple inheritance
situations, is whether a single implementation of a method can honor all
the inherited contracts.
12.3.2. throws Clauses and Native Methods
A native method declaration (see page 74 ) can provide a throws clause
that forces all users of that method to catch or redeclare the specified
checked exceptions. However, the implementation of native methods is
beyond the control of the Java compiler and so they cannot be checked
to ensure that only the declared exceptions are thrown. Well-written
native methods, however, will throw only those checked exceptions that
they declare.
Exercise 12.1 : Create an ObjectNotFoundException class for the
LinkedList class you built in previous exercises. Add a find method that
looks for an object in the list and either returns the LinkedList object
that contains the desired object or throws the exception if the object
isn't found in the list. Why is this preferable to returning null if the ob-
ject isn't found? What additional data if any should ObjectNotFoundExcep-
tion contain?
 
Search WWH ::




Custom Search