File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

UrlyBird: When will the create() method throw DuplicateKeyException ?

 
Eric Chou
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, ranchers:

Due to the instructions, I have to implement a method -- create(). The description tells me that I should allow user to insert a new record or reuse a deleted one. However, this method must throw a DuplicateKeyException which is not specified in the description.

public int create(String[] data) throws DuplicateKeyException;

I read the data file and found that the data record does not have primary key field (I have to use the index of the record location as primary key to uniquely identify a record). From my understanding, I think only when a new record and an existing record have identical contents in all the fields, a DuplicateKeyException will be thrown out.

However, from the name of the Exception, it implies that the Exception should be thrown when a new record has a key duplicating the key of an existing record. Again, the problem is: there is not nature primary key, there cannot be any primary key violence. Am I right?

What do you think about this issue?

Thanks
 
Jethro Borsje
Ranch Hand
Posts: 100
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The most common solution for the DuplicateKeyException issue on this forum seems to be to not ever throw the exception as it is not clear when exactly it should be thrown.
 
Jeffry Kristianto Yanuar
Ranch Hand
Posts: 759
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The most common solution for the DuplicateKeyException issue on this forum seems to be to not ever throw the exception as it is not clear when exactly it should be thrown.


Yes, I didn't throw either.

Jeffry Kristianto Yanuar
SCJP 5.0
SCJA
SCJD (Working on UrlyBird 1.3.2)
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Me neither!

Just don't forget to document why you are doing it.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic