This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes B&S DBMain -- New Exceptions? 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 "B&S DBMain -- New Exceptions?" Watch "B&S DBMain -- New Exceptions?" New topic
Author

B&S DBMain -- New Exceptions?

Kevin Conaway
Ranch Hand

Joined: Jan 27, 2006
Posts: 57
Greetings,

Along with the supplied DBMain.java, my instructions also stated:

Any unimplemented exceptions in this interface must all be created as member classes of the X package. Each must have a zero argument constructor and a second constructor that takes a String that serves as the exceptions description.

Does this mean that I am allowed to modify DBMain.java such that it can throw new checked Exceptions? Or just stating that for the exceptions it DOES throw (RecordNotFound,DuplicateKey), I have to create them as it specifies?

Thanks,

Kevin
Leonid Shalit
Greenhorn

Joined: Apr 29, 2004
Posts: 6
Hi, Kevin!
Adding new checked exception is changing method signature. It will stop other classes related on the same interface from working. (However, you can add unchecked exceptions) So don't do it. They are talking about RecordNotFound and DuplicateKey .


SCJD (B&S in progress)
Kevin Conaway
Ranch Hand

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

Thanks for replying. I figured you can add unchecked exceptions, that feels like a bit of a hack to me though. I am trying to throw some kind of DataAccessException when an IOException occurs while physically reading or writing the database.

Kevin
Kevin Conaway
Ranch Hand

Joined: Jan 27, 2006
Posts: 57
After reading the archived threads and thinking about it myself, it seems there are 2 possible solutions:

- Subclass RecordNotFoundException and DuplicateKeyException for special case IOExceptions.

- Throw a special IOException that extends RuntimeException.

I went with the first and chained the original IOException to the special subclass. I think the exceptions were too important not to be checked.

Kevin
 
 
subject: B&S DBMain -- New Exceptions?