• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 3
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Creator of Enthuware JWS+ V6
Posts: 3411
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply Frits.
Your reply provided some needed clarity.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
I'm just a poor boy, I need no sympathy, because I'm easy come, easy go, little high, little low, little ad
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic