• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

B&S: I have some question about EOFException

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All.

I am working with B&S.
but I have a question about database.
when i read db-2x2.db file using RandomAccessFile. I am not sure how to handle EOFException. Just use catch clause and throw some message ?
or something else ?

thanks for your reply
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think this exception should ever be thrown. When counting the records, you should make sure not to read past the end of the file by using file.getFilePointer() and file.length(). After you know the number of records, there will be no need to read past the end of the file. If you take these precautions and still get an EOFException, then you know something crazy is going on and you should maybe think about closing the app(after notifying the user). In my case, I throw a FatalException if an IOException is caught here(which also catches EOF) because all IOExceptions are bad news.

Matt
 
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Matt is right. I also found out that when I open the file with the "rw" option, the file pointer keeps on going even after the end of the file. So either way its not a good way to detect the end of the file.
 
reply
    Bookmark Topic Watch Topic
  • New Topic