wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes JLS 14.17 throw unchecked exception in instance block Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "JLS 14.17 throw unchecked exception in instance block" Watch "JLS 14.17 throw unchecked exception in instance block" New topic
Author

JLS 14.17 throw unchecked exception in instance block

Ramya Iyer
Ranch Hand

Joined: Jul 29, 2003
Posts: 66
Hi All,

As per JLS 14.17

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.

To understand this and also the instantiation process, I had written a small program...I am getting a compile error at line 8,

javac TestInstantiation.java
TestInstantiation.java:8: initializer must be able to complete normally
{
Why am I getting this error when I am throwing an unchecked exception. Any pointers?

Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Congratulations! It looks as if you found yourself a bug in the compiler.
Make yourself famous and tell Sun about it. (This was a bug way back, and was fixed in about 1.2 - it looks as if it has come back again).

Just send them this code to demonstrate the problem:

[ October 18, 2005: Message edited by: Barry Gaunt ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
A Kumar
Ranch Hand

Joined: Jul 04, 2004
Posts: 979
Hi,

This gives compile error




But this doesnt...



Goes against the point mentioned in the JLS...as in the posts above..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JLS 14.17 throw unchecked exception in instance block
 
Similar Threads
Init and static block
Exception in Instance Initializer
Instance Initializer
que on instance initializer
Dan's mock question