Accdg. to one of my SCJP certification books " if an instance initializer block does not catch a checked exception that can occur during its execution, then the exception must be declared in the throws clause of every constructor in the class".
However, I tried coding it below and the compiler wont allow me to throw a checked exception :
class MyException extends Exception{
public MyException(String msg) { super(msg); }
}
public class MainClass {
public static void main(String args[]){
try {
new InitBlock();
}catch(MyException e){}
}
}
class InitBlock{
boolean test;
{
test = true;
if(test) throw new MyException("throw...");
}
InitBlock() throws MyException {
super();
}
}
Thanks for your help. This is my first posting