This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
As per some books The instance initializer of a class can throw checked exception withou explicitly handling it .. though in that case all the constructors of the class should include that exception in their 'throws' clause. Though this seems logical..doesn't seem to work in practice the Java Compiler does not allow instance initializers to throw checked exception ...without the 'try-catch' block. Can some bosy help me on this. Thanks
mohit joshi
Ranch Hand
Joined: Sep 23, 2000
Posts: 243
posted
0
I also tried the same thing and failed. Good that you brought it up. JLS 8.6. Instance intializers An instance initializer of a named class may not throw a checked exception unless that exception or one of its superclasses is explicitly declared in the throws clause of each constructor of its class and the class has at least one explicitly declared constructor. An instance initializer in an anonymous class (�15.9.5) can throw any exceptions.
Prasad Ballari
Ranch Hand
Joined: Sep 23, 2000
Posts: 149
posted
0
Hi, Thanks for drawing attention for such delicate questions. regards Prasad
Aru Ven
Ranch Hand
Joined: Sep 28, 2000
Posts: 199
posted
0
Thx Rishi & Mohit For the Question & Answer. I did'nt know that........ It's a new info to me. again Thx for sharing.... Aruna
Kartik Shah
Ranch Hand
Joined: Dec 07, 2000
Posts: 102
posted
0
I am also not able to understand the same thing as specified in JLS. 8.6 "An instance initializer of a named class may not throw a checked exception unless that exception or one of its superclasses is explicitly declared in the throws clause of each constructor of its class and the class has at least one explicitly declared constructor. An instance initializer in an anonymous class (�15.9.5) can throw any exceptions" But the compiler does not perform the same way ???
By the way, what is instance initializer? Is it the unnamed block in a class?
Wong KK
Ranch Hand
Joined: Jan 15, 2001
Posts: 52
posted
0
I've also tried it with code. I need to have try-catch statement if there's check exception possibly be thrown in the instance initializer block. Are there anyone have ideas on this?
laoniu, Yes, an instance initializer is an unnamed block within a class definition. It is used to initialize the non-static members of each object created from the class, and is called automatically when you create the object. Static initializer blocks are used to do the same thing for the static members of a class. They look the same, but are preceded with the word <pre><h4>static</h4></pre>.
------------------ ~ Ryan Burgdorfer Java Acolyte in Columbus, OH USA