Both field initializer and instance initializer blocks taken in file order are copied to the beginning of each constructor that doesn't chain to another constructor of the same class.
It is true that instance initializers are executed in source code order in an object just before the second line of the object's last constructor in order of execution
( the first line of that constructor is always super(...) )
Also, the handling of exceptions is different. A checked exception thrown in a constructor can be caught or thrown in that particular constructor ( and in any subclass constructors that call it via super(...) ). A checked exception in an instance initializer block must be declared in a throws clause of every constructor in the class (and at least one constructor must be explicitly declared). A checked exception thrown by an instance variable initializer is illegal. These special rules don't apply in anonymous classes.
I just verified it with JDK 1.5, and having "super();" in a try block gives the error:
Originally posted by George Bolyuba:
I cannot get how can I catch an exception thrown in a super() constructor?
That's it. I was asking right about it. But now I have another question: "Is it correct that any constructor (not chained) receives a copy of byte-code wich is generated by a compiler for each field initializer and instance initializer block?"
Hm... I cannot get how can I catch an exception thrown in a super() constructor? Can you give a code exapmple?
In TIJ (3 Ed.) Bruce Eckel writes that he does not know the way to catch an exception thrown by super();.
Exceptions thrown in constructors are caught or thrown in the code that created the object.
But I cannot catch exception, thrown by super() inside the constructor, that calls super();