Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to deal with the IOException in Data.java?

 
joe lin
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,
as my DBAccess interface haven't declared its methods to throw IOException,
but some of these methods do could thow such exception,so how should I do?
should I throw a runtime exception or return a specified value to the caller? I am go to submit my project, so ... many thanks!
 
joe lin
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,
Does this problem too easy to answer?! but it bother me! so give me a hand,pls. many thanks
 
Paul Bourdeaux
Ranch Hand
Posts: 783
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Throwing a special code back to the caller for IOExceptions is rarely a good design. I was fortunate in my assignment, because all of my methods threw at least one exception, so I wrapped the IOException when appropriate and sent it back tothe caller that way. If you methods have no exception declared in the signature, I would throw a runtime exception and make sure to catch it in the calling code.
 
joe lin
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi paul,
in my assignment,the methods do have exception declared in the signature,but
no IOException.i don't want to wrap IOException into other unrelative exception ,such as DuplicateKeyException. so,i want to find another way to solve this problem.
 
Jon Poulton
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rethrow it as a run-time exception of some sort. Either write your own RunTimeException subclass or use something like IllegalStateException or IllegalArgumentException.
 
joe lin
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi paul and jon,
i think i will throw a runtime exception instead of returning a special value back to the caller. thanks both of you!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic