Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

URLyBird and Exception handling

 
pascal betz
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

just received the assignment for SCJD :-)

how do you handle IOExceptions in the Data.java class ? e.g. in the read(int recNo) method in the DB.java interface only has RecordNotFoundException in the throws clause but of course you will need to access the file in this method.

Did you catch the exceptions and rethrow them as unchecked ?


thanks for your help and a nive week

pascal
 
Jason Moors
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pascal,

This is a common question, if you search the forum you will find a number of posts on the subject.

Basically you have two approaches, either of which you want to learn about 'chained exceptions'. This enables you to use the getCause method.

1) Catch IOException in method and throw an Unchecked RuntimeException.
2) Catch IOException and throw an new Exception whic is sub-class of RecordNotFoundException.

Regards
Jason
 
pascal betz
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Jason

thanks for your help. I prefer the the unchecked Exception version. Making sub-classes of RecordNotFound for the "something with the file is not working" case seems strange to me :-)


pascal
 
Daniel Massie
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whatever option you choose, make sure you document it in your choices document.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic