Hello there, I am trying to create a singleton object. I am getting that object in the class and using it. Now, if there is an exception thrown while creating that singleton object, how can I handle that.. Please refer follwing code for better understanding of the issue-
If there is an exception thrown while getting instance of pReader, how can I handle that?
You could try and intialize the static variable from within a static initializer block and wrap the getInstance() call with a try-catch block, but why would you want to? If an Execption occurs at that level it seems to me that it would be pretty much fatal, so how would you propose to correctly handle it?
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Actually I am trying to access pReader from main method as well as from other methods of class abc. Hence I have declared pReader as static at class level. Is there a way to handle this kind of scenario?