This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
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 ?
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
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 ]
author and jackaroo
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
Joined: Jul 03, 2003
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
author and jackaroo
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 ]