This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach 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

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "B&S DBMain -- New Exceptions?" Watch "B&S DBMain -- New Exceptions?" New topic

B&S DBMain -- New Exceptions?

Kevin Conaway
Ranch Hand

Joined: Jan 27, 2006
Posts: 57

Along with the supplied, 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 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?


Leonid Shalit

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 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.

I agree. Here's the link:
subject: B&S DBMain -- New Exceptions?
Similar Threads
Exception Handling and Throwing
Exception Handling
constructors and exceptions
try catch in constructor
Interface provided by Sun