Hi Eva,
The question is how can duplicate key error occur? The client give me a record to add and you never get duplicate record! As I said before, there can be identical rooms in the DB and it is OK.
Sun have stated in the past that some parts of the assignment deliberately emulate users who are asking for things that contra-indicate either other parts of the assignment or even just what we would expect. In real life, we would be expected to go back to the customer and talk through the problems with them. Sun want to see that
as developers we can spot the issues, think of solutions, and then describe the solution we decided to go with in our design decisions document.
So, yes, it is possible that you could have two identical rooms, which makes the DuplicateRecordException redundant.
So, is it a design decision to use this exception for DB access error etc.?
As B Chen says, this is a design decision, but it might not be the best design decision.
Think about it from the perspective of a junior programmer who has just joined the company and has to work with your Data class. They start looking at the create() method, and notice that it can throw a DuplicateRecordException. Why would they expect that to mean anything other than the fact that there is a duplicate record? Telling them that a DuplicateRecordException might be thrown if there is a duplicate record, or if there was a permissions problem, or if there was an IO problem, or if there was a .... is just going to confuse them.
Wouldnt it be better if the Create method threw DuplicateRecordException
and DBAccessError? (Hint, take a look at what
java.lang.RuntimeException can offer you.
Regards, Andrew