• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Back again, About Exception Question

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic