• 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

NX:IOExceptions What to do?

 
Ranch Hand
Posts: 435
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a static class block in my Data class to read the db schema and load the cache with it's initial records. My problem is what to do If I receive an IO exception/FileNotFoundException reading from the db file.
Stop the Server or just log a message. Any ideas ?
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Tony,
Do you have a GUI for your server? Can you display a message telling the user what is wrong? Can you prompt them for the location of a valid database file?
In my opinion, if you cannot get some sort of fix from the user, then you may as well shut down the server because it is not going to provide anything to the clients. If you can get a fix from the user, then prompt them for the fix, then try again.
Regards, Andrew
 
Tony Collins
Ranch Hand
Posts: 435
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But when a static intiliser block throws an Exception whom is it caught by ?
Is a static block a bad choice to set up the initial cache in then ?
Cheers
Tony
[ July 28, 2003: Message edited by: Tony Collins ]
 
Andrew Monkhouse
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Tony,
Your class still has to be created doesn't it? So you can catch the exceptions from the static block when you create the instance of the class.
Regards, Andrew
 
Tony Collins
Ranch Hand
Posts: 435
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I changed the static block to a static method(startServer) as I understand the static block, is called when the class is loaded into the JVM not when an instance is created. I have control of when the class is initilised then.
I have read several posts regarding traping IOExceptions( which I would think would never happen anyway) wondered if anyone agreed that IO Exceptions should really be dealt with in the method that throws them. As actions like closing files down should be carried out at that point, maybe faliure of server to intilise could be reported by a more general Exception.
Tony
 
Andrew Monkhouse
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Tony,
Sorry, wasn't thinking clearly last night. The Java Language Specification tells us that static initializers cannot throw checked exceptions:

Static initializers (�8.7), class variable initializers, and instance initializers or instance variable initializers within named classes and interfaces (�8.3.2), must not result in a checked exception; if one does, a compile-time error occurs.


So you cannot throw the IOException or FileNotFoundException from the static initializer.
Regards, Andrew
[ July 28, 2003: Message edited by: Andrew Monkhouse ]
 
Tell me how it all turns out. Here is a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic