Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript 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
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Unneeded exception?

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello to everyone!

I've just started working on my assignment (URLyBird 1.3.1) and there is one thing that confuses me a bit. Maybe someone came across it too. I am supposed to throw a DublicateKeyException in method which creates a new record. The instruction doesn't say a word about it mentioning only that it MUST be implemented. The thing is that I am going to use an index number as a record key, and it will be determined by position in the file. On the other hand, I don't see any problems if two identical records will be created (since they will have distinct locations in the file and therefore distinct keys) and I cannot think of any realistic scenario in which I might need this exception.
Anyway I am going to implement it, declare it in the method's signature and then just forget about it. Will it make The Assessor happy, that's the question...
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Garik,

First of all: Welcome to the Ranch!

You have the same assignment like me, I had the 1.3.1 version of URLyBird too

My create-method in Data-class looked like this

But the exception wasn't thrown anywhere from the create-method.

Of course you (have to) mention it in your choices.txt that you didn't throw a DuplicateKeyException, because .... (if you use your common sense, you can easily find a reason why). And the accessor will be very happy

If you have any other doubts/questions, just ask and everybody here will be glad to help you.
Kind regards and good luck,
Roel
 
Garik Ustinov
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roel, thanks for sharing and for the welcome!
I feel much safer now.
 
Ranch Hand
Posts: 489
2
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Roel

I've chosen dont reuse ID..so I wont throw DuplicateKeyException in my createRecord(String[] data).
But what about javadoc ? What I should writte in javadoc....I mean....@throws DuplicateKeyException ???
Regards
 
Bartender
Posts: 3648
16
Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes Fernando, you would still do "@throws DuplicateKeyException" in the javadoc for your create method. This is because the create method signature has DuplicateKeyException.

Now whether the exception is "physically" thrown or not, you say that in choices.txt file and in the javadoc description.
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Fernando,

In my interface:
I added description in javadoc, because it is the interface and you have to describe your complete method signature, so it has nothing to do with your implementation (it could be thrown or not from your Data class), but because it could be thrown you have to mention it in your javadoc.

in my Data class:
From my data class no DuplicateKeyException is thrown and why I decided not to throw it, is described only in my choices.txt. I don't agree on this one with K. Tsang, because in an interface you should mention what your method is supposed to do ("create a new record and throw DKE if a duplicate key is detected") and not how it is implemented.
And normally you program against an interface and you don't have any knowledge about the implementation that will be used, so because the create-method in the interface is throwing DKE, you have to handle this exception in your program (if you would call this method, so not in this assignment).

Kind regards,
Roel
 
Fernando Franzini
Ranch Hand
Posts: 489
2
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Roel

I've done the same about javadoc and {@inheritDoc}. But another question is about RuntimeException that some methods throws.
So..should I put this RuntimeException javadoc inside sun assignment interface or in my own implementation class ?
Like this:


 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Fernando,

Because I used a record cache (and not direct file access) I don't have that problem that a read could fail

But i think you could at these exceptions to your interface without any problem, because if in the future they are replacing the flat file by a MySQL database, DataMySQL will be created and if an error occurs during the read, you will have to throw a DataBaseException too. You are working in an interface, so you have to be general in your description: do not write something like "throws DataBaseException if error occured while reading the database file", but write instead "throws DataBaseException if error occured while retrieving the record" (or something similar).

I have done something similar in my init-method:


And that should do it.
Kind regards,
Roel
 
Fernando Franzini
Ranch Hand
Posts: 489
2
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

But i think you could at these exceptions to your interface without any problem,......


But this is not my interface....this is sun assignment interface !!
So...should I add this javadoc there ?

Regardss.
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Fernando,

I guess there is no harm in adding javadoc to sun's interface (because i added some javadoc at class level and I didn't fail). I didn't add javadoc comments at method level. My own interface had all methods from sun's interface (sometimes with a small adjustment, but it kept a valid override of course) and had some extra own methods. All the javadoc of these methods were in my own interface.

Kind regards,
Roel
 
Fernando Franzini
Ranch Hand
Posts: 489
2
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks again Roel
See you around
 
Ranch Hand
Posts: 221
Scala Python Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Roel,


Thanks for sharing your point of view regarding this.
I have URLyBird 1.1.3 and my interface looks like



and I was scratching my head wondering about this using the same reasoning Garik stated.


Best,


Carlos.
 
    Bookmark Topic Watch Topic
  • New Topic