• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Exception Handling - Overloading vs Overriding

 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi all,
I want to know suppose a method throws an Exception. Then what Exceptions can be thrown by an Overriding method and an Overloaded method ?

I am totally confused.
 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Amit,
An overriding method can throw the same exception as the method it is overriding, a sub exception of that exception or no exception at all. In the case of an overloading method, I'm pretty sure that it does not matter what type of exception the overloading method throws. As at runtime, the compiler will check the argument types and when it finds the method it's looking for, the exception it throws (if any), is of no concern to the compiler.
Hope this helps
Brian C
 
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The overloaded method can throw any exception thrown / not thrown by the method it overloads.
In the case of the overriding, the overriding method can only throw those checked Exceptions (and subclasses of these Exceptions) that are thrown by the method it overrides. The overriding can throw any Runtime Exception.

 
amit sanghai
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Brian and Bharatesh. That really helped.
 
I can't renounce my name. It's on all my stationery! And hinted in this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic