wood burning stoves*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes how to deal with the IOException in Data.java? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "how to deal with the IOException in Data.java?" Watch "how to deal with the IOException in Data.java?" New topic
Author

how to deal with the IOException in Data.java?

joe lin
Greenhorn

Joined: Dec 07, 2004
Posts: 28
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!


Looking for better solution...<br />SCJP1.4
joe lin
Greenhorn

Joined: Dec 07, 2004
Posts: 28
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

Joined: May 24, 2004
Posts: 783
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.


“Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.” - Rich Cook
joe lin
Greenhorn

Joined: Dec 07, 2004
Posts: 28
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

Joined: Jun 09, 2004
Posts: 27
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

Joined: Dec 07, 2004
Posts: 28
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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to deal with the IOException in Data.java?