File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes OCEJWCD study companion ch4 q13 (ServletContextAttributeListener methods - checked exceptions) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "OCEJWCD study companion ch4 q13 (ServletContextAttributeListener methods - checked exceptions)" Watch "OCEJWCD study companion ch4 q13 (ServletContextAttributeListener methods - checked exceptions)" New topic
Author

OCEJWCD study companion ch4 q13 (ServletContextAttributeListener methods - checked exceptions)

Tony Sitterly
Greenhorn

Joined: Apr 15, 2009
Posts: 3

I am trying to understand why the listener methods are not allowed to throw any checked exceptions?
I can't seem to find any reference for this in the chapter text?
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1687
    
  25

Hi Tony,

I am trying to understand why the listener methods are not allowed to throw any checked exceptions?

The obvious answer is because the interface doesn't allow this.

On the other hand if you think of it: why would you want to throw a checked exception? Could you catch it in your business logic and do something about it? Not really, don't forget that it is the web-container calling these methods because of an event in your business logic. So if you throw a checked exception what should the web-container do?

Regards,
Frits
Tony Sitterly
Greenhorn

Joined: Apr 15, 2009
Posts: 3

Thanks for your reply Frits.
Your reply provided some needed clarity.
jalil idrissi
Greenhorn

Joined: Feb 05, 2013
Posts: 6
The answer is actually in SCJP. When you override a method, you can only throw a narrower exception. It means in the signature you declare that you "throws" a subclass of the overriden method, or you don't declare anything at all.


OCEJWCD 6
OCPJP 7
 
GeeCON Prague 2014
 
subject: OCEJWCD study companion ch4 q13 (ServletContextAttributeListener methods - checked exceptions)