Meaningless Drivel is fun!*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes DuplicateKeyException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "DuplicateKeyException" Watch "DuplicateKeyException" New topic
Author

DuplicateKeyException

Mike Tilling
Ranch Hand

Joined: Feb 17, 2006
Posts: 86
Could you help please

in the UrlyBird assignement, the create method throws a DuplicateKeyException, in the database file there is no field for "key",

the database fields are

1-name
2-location
3-Size
4-smoking
5-Rate
6-Date
7-owner

Under which condition the "DuplicateKeyException" should be thrown when creating a new record?

Best Regards
Mike
Kevin Conaway
Ranch Hand

Joined: Jan 27, 2006
Posts: 57
Hi Mike,

Does it need to be thrown at all? Just because your interface declares the exception, it doesn't mean you have to throw it.

You can read my thoughts on the subject, but I believe this is an overt attempt by Sun to trip you up a little.

Kevin
[ February 17, 2006: Message edited by: Kevin Conaway ]
Mike Tilling
Ranch Hand

Joined: Feb 17, 2006
Posts: 86
Hi Kevin

In the assignement they said that it must be thrown

Thanks
Mike
Kevin Conaway
Ranch Hand

Joined: Jan 27, 2006
Posts: 57
Mike,

When you say it must be thrown, what do you mean? Do you mean the your interface declares DuplicateKeyException? Or is there a line of text in your spec somewhere saying, "Throw DuplicateKeyException if x..."

Kevin
Mike Tilling
Ranch Hand

Joined: Feb 17, 2006
Posts: 86
Kevin
Yes, there is a line of text in my spec saying that create method must throw
DuplicateKeyException :

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

Many thanks
Kevin Conaway
Ranch Hand

Joined: Jan 27, 2006
Posts: 57
Mike,

That is just an interface declaration. Like I said, just because the method declares the Exception, it does not mean you have to throw it.

The following is perfectly legal Java code:



Kevin
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: DuplicateKeyException