// Creates a new record in the database (possibly reusing a // deleted entry). Inserts the given data, and returns the record // number of the new record. public int create(String  data) throws DuplicateKeyException;
What is curious about this is that the data is supposed to be stored in a file. All the methods I have seen to write to a file will throw an IOException in certain error conditions. But according to this interface specification, the only exception I am permitted to throw is DuplicateKeyException. What am I supposed to do if the file system causes the write() method to throw an IOException? I want to return an accuarte error to the user, not DuplicateKeyException.
In the Data class, which implements this interface, I tried doing this:
but got an error because the interface that it is implementing only throws DuplicateException, not IOException.
I have similar problems with some of the other methods in this interface which produce IOExceptions.
Is it OK to change the interface to also throw IOException? And if not, how do you handle this type of error if it occurs? [ May 07, 2005: Message edited by: Lara McCarver ]
Joined: Jun 25, 2004
One way is catch the IOException, and return an error value (e.g -1).
Current Status:<br /> <br />SCJP 1.4<br />SCJD (in progress)
Joined: Nov 22, 2008
One possibility is that any new exceptions you want to throw from the class that implements DBMain is to extend them from RuntimeException. RuntimeExceptions do not need to be declared in the throws clause of a method.
As long as you state in your choices that you had to implement them as RuntimeExceptions due to the limitation of the DBMain interface you should be fine.
Joined: Feb 23, 2004
Ditto what Matt said. That's how I handled it. But be SURE to document exactly why you did it that way, and other ways you considered.
B.S. University of Wisconsin<br />SCJP 1.4 (85%)<br />SCJD 1.4 (92%) B&S Contractors