• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

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: 4897
60
  • 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.
 
Live ordinary life in an extraordinary way. Details embedded in this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic