• 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

about Exception handling.

 
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, all, see the following code, the question comes from
<code> http://valiveru.tripod.com/java/jvaltest.html
</code>

The answer is C and D, I thought it is B,C and D.
Any idea?
Thanks in advance.
Guoqiao
[This message has been edited by Guoqiao Sun (edited July 31, 2001).]
 
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guaquio,
SubException is a subclass of BaseException , so in case aMethod() throws a SubException it can aways be cast to BaseException in MyClass (code B). BaseException can always account for the SubException . That's the same reason why code D is also correct .
And hey thanx for the number line (Math.floor()).
Ashish.
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Youre right, although added useless unchecked exception into throws clause in example B it will compile (note that E does not!)
I think it should be B,C,D.
------------------
Antti Barck
It Solutions Consultant, NSD Oy
 
Guoqiao Sun
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Ashish and Antti, I am confirmed of the question now.
Guoqiao
 
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so is the final Answer B, C and D ??
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Swati!
At least B,C and D do compile.
------------------
Antti Barck
It Solutions Consultant, NSD Oy
 
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could any one give me some explanation why C is right?
 
Guoqiao Sun
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, david, C is actually the same as B, since throwing RuntimeException is really meaningless.
Guoqiao

Originally posted by david hu:
Could any one give me some explanation why C is right?


 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guoqiao!
RuntimeException is not checked Exception, thus "throws RuntimeException" is really meaningless. Right?!

------------------
Antti Barck
It Solutions Consultant -- NSD Oy
[This message has been edited by Antti Barck (edited July 31, 2001).]
 
Guoqiao Sun
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, Antti, you are right, RuntimeException is not checked exception. See the following chart:

Those under RuntimeException and Error are unchecked exceptions, the rest are checked exceptions.
Hope it helps.
Guoqiao

Originally posted by Antti Barck:
Hi Guoqiao!
RuntimeException is not checked Exception, thus "throws RuntimeException" is really meaningless. Right?!


 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic