This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt Regarding Anonymous Inner Classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt Regarding Anonymous Inner Classes" Watch "Doubt Regarding Anonymous Inner Classes" New topic
Author

Doubt Regarding Anonymous Inner Classes

Ravi Pinnaboyina
Greenhorn

Joined: Feb 19, 2007
Posts: 11
All constructors must declare the uncaught checked exceptions, if any.

Instance Initializers in anonymous classes can throw any exception.


I couldnt understand the second point, can someone give me an example....
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

It's possible that initializing an anonymous class might throw a checked exception. A throws clause cannot be added to the constructor, because anonymous classes have no named constructers. However, these checked exceptions still need to be caught or declared at some higher level.

For example, the code below has an anonymous class that might throw an exception in its initialization. No throws clause is possible for the anonymous constructor, so the throws class must go elsewhere -- in this case, in the enclosing class's constructor (because this anonymous class is instantiated with the instantiation of the enclosing class).

For details on the troubled history of this, see Throwing Checked Exceptions during Instance Initialization by Doug Dunn.
[ February 21, 2007: Message edited by: marc weber ]

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt Regarding Anonymous Inner Classes