This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Hands On Software Engineering with Python and have Brian Allbey on-line!
See this thread for details.
Win a copy of Hands On Software Engineering with Python this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

Can I leave out exceptions in interface implementation?  RSS feed

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

This question has probably been asked before, but I did not manage to find it in the archives:

My assignment (B&S 2.3.2) states that I must implement a given interface. Some of the methods in the interface are defined to throw specific exceptions which I feel would not necessarily have to occur in my implementation.

For example, my isLocked() method is defined in the interface as follows:



Since I only allow records that are found in the database to be locked, the exception is never thrown for locked records and according to the "contract" I am allowed to return false for all other cases (unlocked records and non-existent records(?)). So would I be cutting corners if I remove the RecordNotFoundException from the implementing class' method?

Thanks for your thoughts,

Frans.
[ December 29, 2004: Message edited by: Frans Janssen ]
 
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read my answer to this post
 
Frans Janssen
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Steven Bell:
Read my answer to this post



Steven,

Thanks for your reply. It is indeed a good suggestion to at least declare that the method throws the exception even if it doesn't. (Currently my code wasn't doing that )

However, I still like some opinions on if the assessors will accept that defined exceptions are never thrown in the implementing class.

Frans.
 
Ranch Hand
Posts: 1033
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Frans Janssen:

Steven,

Thanks for your reply. It is indeed a good suggestion to at least declare that the method throws the exception even if it doesn't. (Currently my code wasn't doing that )

However, I still like some opinions on if the assessors will accept that defined exceptions are never thrown in the implementing class.

Frans.



If your assignment is anything like the URLyBird assignment you will not have a reasonable primary key. In that case you will have no occasion where a DuplicateKeyException could possibly be thrown. You still need to declare it as a possible exception since the interface does, and you can't change the interface, but you just can't throw it. The only thing that will be concerned about this is checkstyle, and you can turn off that check.
 
Morning came much too soon and it brought along a friend named Margarita Hangover, and a tiny ad.
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!