Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Ron Newman - SCJP 1.2 (100%, 7 August 2002)
Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
Ron Newman - SCJP 1.2 (100%, 7 August 2002)
If a throw statement is contained in an instance initializer (�8.6), then a compile-time check ensures that either its value is always an unchecked exception or its value is always caught by some try statement that contains it, or the type of the thrown exception (or one of its superclasses) occurs in the throws clause of every constructor of the class.
Static initializers (�8.7), class variable initializers, and instance initializers or instance variable initializers within named classes and interfaces (�8.3.2), must not result in a checked exception; if one does, a compile-time error occurs. No such restriction applies to instance initializers or instance variable initializers within anonymous classes (�15.9.5).
Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
JLS 11.2
The last two paragraphs of section 11.2 on page 221 should be amended to read. This resolves an apparent discrepancy with JLS 8.6 :
Static initializers (�8.7), class variable initializers, and instance variable initializers within named classes and interfaces (�8.3.2), must not result in a checked exception; if one does, a compile-time error occurs. No such restriction applies to instance initializers or instance variable initializers within anonymous classes (�15.9.5).
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.
Ron Newman - SCJP 1.2 (100%, 7 August 2002)
Ron Newman - SCJP 1.2 (100%, 7 August 2002)
Ron Newman - SCJP 1.2 (100%, 7 August 2002)
Ron Newman - SCJP 1.2 (100%, 7 August 2002)
Ron Newman - SCJP 1.2 (100%, 7 August 2002)
Originally posted by Ron Newman:
Dan (or anyone else): Does either my code sample or yours compile successfully with the latest 1.4 compiler?
[ September 04, 2002: Message edited by: Ron Newman ]
Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
Originally posted by Ron Newman:
Anthony -- but does it print "6" before BANG, as Vin Kris claims?
I don't have 1.4 so I can't play with it myself. I sure hope Sun doesn't ever put a question like this on the exam, given that they only recently figured out how they really wanted it to work.
[ September 04, 2002: Message edited by: Ron Newman ]
Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
Ron Newman - SCJP 1.2 (100%, 7 August 2002)
SCJP2. Please Indent your code using UBB Code
Originally posted by Ron Newman:
Anthony -- but does it print "6" before BANG, as Vin Kris claims?
Originally posted by Vin Kris:
sorry guys... i wasn't clear in the post. my mistake.
I meant to say that BANG is also printed if the throw statement was uncommented. Guess i should have written two separate lines of output.
The output i got with BANG uncommented was ...
25134Exception in thread "main" java.lang.Exception: BANG
at P.m1(S.java:2)
at R.<init>(S.java:19)
at S.main(S.java:29)
[ September 05, 2002: Message edited by: Vin Kris ]
Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
Prior to Java 1.4, the code example used in this question would not compile. The bug was fixed in version 1.4. The bug ID is 4409174.
Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |