• 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

Confusion

 
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Please help me to understand what is wrong with answer �B�. given answer is �C�, �D�.

Given that method aMethod() throws BaseException, SubException and RuntimeException of the following exception hierarchy

Which of the following are legal

A.public class MyClass {
public void myMethod(){
aMethod();
}
}
B.public class MyClass{
public void myMethod() throws BaseException,RuntimeException{
aMethod();
}
}
C.public class MyClass{
public void myMethod() throws BaseException{
aMethod();
}
}
D.public class MyClass{
public void myMethod() throws Exception{
aMethod();
}
}
E.public class MyClass{
public void myMethod() throws RuntimeException {
aMethod();
}
}

regards
vivek

[This message has been edited by Vivek Shrivastava (edited August 04, 2000).]
[This message has been edited by Vivek Shrivastava (edited August 05, 2000).]
[This message has been edited by Vivek Shrivastava (edited August 05, 2000).]
[This message has been edited by Vivek Shrivastava (edited August 05, 2000).]
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The order of catch should be more specific exeception followed by less specific exceptions.
for example,
try
catch IOException
catch Exception
is legal.
Where as the following is illegal.
try
catch Exception
catch IOException
The compiler will complain "catch not reached" for the second catch.
 
Vivek Shrivastava
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I just edited my post so that u can get a better picture of hierarchy.
Please help me.
vivek
 
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
I dont see anything wrong with answer "B".
The method does not have to specify "throws RuntimeException". ["RuntimeException" is not a checked exception anyway.]
But if it does, it is perfectly legal.

[This message has been edited by vasansrini (edited August 05, 2000).]
 
Ranch Hand
Posts: 289
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Vivek,
I also feel that B is as such legal.There should be no harm in throwing runtime exception, even though it is not neccessary.
Herbert
 
Any sufficiently advanced technology will be used as a cat toy. And this tiny ad contains a very small cat:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic