Exception throw by constructors
807597Jan 17 2005 — edited Jan 18 2005Hello all,
I have a question regarding throwing Exceptions from java constructors.
I know that's possible to throw Exception from java constructors, but this is recomended or what kind of precautions should I have?
I have an object SampleObjec that needes to be initialized. The initialization process, for example reads a properties file, file that may not exists, in this case I will not let the object to be instantiate.
For Eg.
public class SampleClass {
public SampleClass throws Exception {
//Read the file and create some new objects
Vector vec = new Vector();
// if something goes wrong I'll throw an Exception
if ( notSuccessfull ) {
throw new Exception("Error");
}
SringBuffer stBuff = new StringBuffer();
}
What the consequences if the notSuccessful flag is true??
Thanks in advance,
Jo�o Pereira