Any methods that throw RecordNotFoundException should do so if a specified record does not exist or is marked as deleted in the database file
Originally posted by S Bala:
Hi Max,
I can understand in case of checked exceptions. But, in this scenario we are forced to rethrow an IO exception as a runtime exception.
where do we handle that?
thanks.
Originally posted by Tony Collins:
I also wondered about createRecord and upDateRecord, should they throw overflow exceptions if the user tries to create/update a field with too many fields? This seems to be the norm in Java Buffer API's from what I can see.
Tony
// Reads a record from the file. Returns an array where each
// element is a record value.
public String[] read(int recNo) throws RecordNotFoundException;
Any methods that throw RecordNotFoundException should do so if a specified record does not exist or is marked as deleted in the database file.
Originally posted by S Bala:
Hi Max,
Here is one of the method signature in the interface provided by Sun looks like --
So any IOExceptions we get need to be chained back as RuntimeException. This is true for all the methods in the data class which implements the interface.
SB
Originally posted by Tony Collins:
I supose the jist of my question is that should every method you write act like a proffesionally written API as in 1 or as in 2 a bit of a bodge. And in that last sentance I think I have answered my own question.
Any unimplemented exceptions in this interface must all be created as member classes of the suncertify.db package. Each must have a zero argument constructor and a second constructor that takes a String that serves as the exception's description.
Tony,
Careful about the chaining mechanism, as my assignment says follows
quote:
--------------------------------------------------------------------------------
Any unimplemented exceptions in this interface must all be created as member classes of the suncertify.db package. Each must have a zero argument constructor and a second constructor that takes a String that serves as the exception's description.
--------------------------------------------------------------------------------
Max - Thanks for your help.
My initial reluctance to subclass RecordNotFoundException to capture an IOException was because, they are having different behaviors. You can only subclass if the parent class has a generic behavior. It is clearly stated that one should throw a RecordNotFoundException, if the record has been deleted, or not available (record number is not present).
Thanks,
SB
I guess I'm having a hard time understanding why it has it be a RuntimeException. It could
1) be a special subclass of RecordNotFoundException(say IORecordNotFoundException), or,
2) a regular, non-runtime exception chained to the RecordNotFoundException.
Both of these are pretty good answers, though I prefer the second. I don't think that throwing RuntimeExceptions are really the way you want to approach this. In a large sense, RuntimeException defeat the whole point of checked Exceptions, because your client can't(and shouldn't) catch them. What you're doing in throwing them, effectively speaking, is masking an explicit exception. Not really a good idea, IMO.
Now the big issue is that one of our methods throws no exception at all (public long[] findByCriteria(String[] criteria)). What to do then ? Just "eat" the IOException ? It would be bad too IMO
Originally posted by Philippe Maquet:
Hi Max,
BTW, you never answered to my last reply to you in this thread. You pointed out there a so big issue that it would be great if your were willing to check it.![]()
[ July 31, 2003: Message edited by: Philippe Maquet ]
If you interpret the requirements religiously, then maybe Sun is trying to give you a hint on the implementation they'd like to see here. That is, maybe they're telling you there shouldn't be any IO in this method. And if that's true, maybe they expect you to add the record logically. That is, maybe they expected you to cache the db in memory, and simply add/remove from that store: thus, there's no IO.
Don't make me look through that whole thread again. Which post?
Originally posted by Tony Collins:
Thanks Max,
Your sixth option is interesting. But the db file is used by another system. We don't know what this system is or how often it runs, therefore we couldn't really assume how often the underlying database is required to be updated.
Tony
And if that's true, maybe they expect you to add the record logically. That is, maybe they expected you to cache the db in memory, and simply add/remove from that store: thus, there's no IO.
What will happen if we get an IO exception when we write to the db from the cache ?
Originally posted by Philippe Maquet:
Hi Max,
I think that S Bala refers to a design which uses a write cache as you mentioned yourself when you wrote :
If a separate thread handles writes in the file from the write cache, an IOException cannot be thrown from its run() method. The only solution I can see is to somehow mark the given record as corrupted (in a HashSet ?), remove it from write and read caches and make sure that any attempt to further read or update it will throw the IOException (in any acceptable way discussed in previous posts).
Does it make sense ?
Best,
Phil.
System exceptions: Most often system exceptions are thrown as subclasses of RuntimeException by the JVM. A NullPointerException, or an ArrayOutOfBoundsException, for example, will be thrown due to a bug in the code. Another type of system exception occurs when the system encounters an improperly configured resource such as a misspelled JNDI lookup. In this case, it will throw a checked exception. It makes a lot of sense to catch these checked system exceptions and throw them as unchecked exceptions. The rule of thumb is, if there isn't anything you can do about an exception, it's a system exception and it should be thrown as an unchecked exception.
Originally posted by Vlad Rabkin:
Hallo Tony, Max, Phil,
Here is a link:
http://www-106.ibm.com/developerworks/java/library/j-ejbexcept.html#8
You can find there following:
What can a user do about if Remote or IO Exception happen?
The best what he down close client application and run it again (in case of RemoteException), or ask System Admin to restart the server (in case of I/O
problem on the remote server)
I know it is kind of excuse to use a un-checked exception,
I beleive the RecordNotFoundException has nothing to do with I/O problems,
it would even more confuse client developer.
Vlad
if there's a IO error ? IMO, an IORecordNotFound exception makes perfect sense, because it conveys both the fact that the record was not found, and that there was an IO problem.
Warning : methods which encounter a IOException throw a DataIOException (runtime). Please check the throws clauses in the detailed descriptions of methods.
Throws DataIOException (runtime) if a java.io.IOException occurs.
Warning : methods which encounter a IOException chain it in one of their checked exceptions. If a method does not throw any checked exception, null is returned if a IOException occurs. So please check in the detailed descriptions of methods all exceptions mentioned in the throws clauses as well as the return clause in case no exception is thrown.
Returns: an array of record numbers that match the specified criteria, or null if a java.io.IOException occurs.
Throws DuplicateKeyException if the new record violates the table primary key or if a java.io.IOException occurs. Use Exception.getCause() to distinct both cases.
Originally posted by Philippe Maquet:
Hi Max,
Thanks for your reply, I really enjoy this discussion.
You'll agree that the main (and only ?) benefit of checked exceptions over runtime ones is that compiler will enforce the programmer to catch (and handle) the former ones : the programer doesn't need to dig into your doc to check the @throws clauses and he may even be absent-minded as I am.![]()
But, by using the exception chaining facility, we loose that benefit anyway (IMO) because if the programer catch the well-known checked exceptions defined in the interface without checking their getCause(), the application will have a quite weird behaviour to the user :
DuplicateKeyException caused by IO - message : "That key exists already in file. Try again with another key." (while the user knows the key is unique) RecordNotFound caused by IO and thrown in updateRecord() just after a succesful read - message : "Record number " + recNo + " does not exist." (while the user knows that the record exists)
Now returning null from findByCriteria() in case of IOException, will lead in direct line to a NullPointerException if the programer does not pay attention to it.
So I think we are quite far from the benefit of checked exceptions as mentioned above.
Originally posted by Vlad Rabkin:
Hi,
Just one comment: in my assignement there null is definf for findbyCretireia
for the case where nothing was found (So I will never get NullPointerException). A user will think there no records in the database, but actually there is something wroth with database...
Vlad
rubbery bacon. rubbery tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|