• 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

Enthuware Object Wise Mock Question on Interface And Exceptions Confusion

 
Greenhorn
Posts: 19
IntelliJ IDE Tomcat Server Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Here is code snippet from Enthuware exam simulator



m1() implementation is neither throwing IOException and SQLException. What trick i am missing? Can the overriding method not throw any exceptions at all?

Thanks,
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ben Prequel wrote:Can the overriding method not throw any exceptions at all?


Of course. The only thing it can't do is throw a checked exception that is not declared by the parent method.
 
Ben Prequel
Greenhorn
Posts: 19
IntelliJ IDE Tomcat Server Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Joane,

Thanks a ton. Does somewhere JLS specify this clause for implementing methods of interfaces or it's basic rule of overriding?

Thanks,
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ben Prequel wrote:Does somewhere JLS specify this clause for implementing methods of interfaces or it's basic rule of overriding?


I would imagine the JLS does specify this somewhere. The rules for implementing interface methods and overriding super class methods are the same (or at least I can't think of any differences off the top of my head), but they may be specified in separate sections of the JLS.
 
Enthuware Software Support
Posts: 4810
52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, it is allowed to not throw any exception at all.
The only rule is that an overriding (or implementing) method cannot throw a more generic exception than the overridden (or declared in interface) method. The only way you can satisfy this rule in the given situation is to not throw any exception.


 
Ben Prequel
Greenhorn
Posts: 19
IntelliJ IDE Tomcat Server Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Paul,

Thanks. I have got the confusion clear.

Thanks.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic