This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
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

Back again, About Exception Question

 
Jesse Xie Y.S.
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I prefer to implement a business logic layer between user client and database, and I am just confusing about how could I deal with so much exception. Should I ignore the IOException? Could I ignore the RemoteException? Or maybe I could just transform it into other exception such as RecordNotFoundException or RoomNotFoundException?

Any help. TKS very much.
 
Thomas Paul Bigbee
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://java.sun.com/j2se/1.4.2/docs/guide/lang/chained-exceptions.html

The link above will take you to a good article on how to chain exceptions.

You can't ingnore Checked Exceptions, and you can't specify any new/broader exceptions when implementing an interface, you can however,chain exceptions (throw a RuntimeException) from within the IOException catch block, with the Cause and Stack information from the original exception, and handle it in the business tier

Hope this helps
Tom
 
Jesse Xie Y.S.
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, good day every one. I really don't know how to deal with IOException.

public synchronized long[] findByCriteria(String[] criteria) {
long[] result;
try{
dataFile.seek(getLocation(recNo));
... ...
return result;
} catch (IOException ioe) {
ioe.printStackTrace();
//If have exception return null;
return null;
}
//If have no result,return 0 length array
return new long[0];
}

how do you think?
 
Jesse Xie Y.S.
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Thomas, after I read over this forum about the IOException, I found that it is really a big problem. and now, I want to try your suggestion.

So I just create a new DataException and extends from RuntimeException, and I will catch it on business layer.

I think it's normally a fetal error about reading file, because my program will make sure that the file exist before create new Data instance.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic