• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception Handling and Throwing

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

In my assignment (B&S 2.3.3) my interface is called DBMain and the implementing class is called Data. In my Data class I handle exceptions such as IOExceptions and re throw them as DataException which is a RuntimeException.

I've add the DataException as part of the throws clause like so...
Data.java


The DBMain.java was specified like so...


I'm wondering if I'll be breaking any "must" requirements in the assignment by adding this Exception. What does everyone else think? Has anyone done this?

Cheers,
Matt.
 
Kai Witte
Ranch Hand
Posts: 356
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,

the general convention is that RuntimeException and subclasses shall not be declared to be thrown in the signature. Some people disagree, but I like this convention and I follow it.

In your case you should follow it either way, because otherwise you would take an unnecessary (though low) risk of an automatic failure.

Conan
 
Jeff Bosch
Ranch Hand
Posts: 805
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Matt -

I think you're asking for trouble by adding the second exception. While you may not automatically fail for this change (though you may, I'm not sure), you would probably lose points.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic