• 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

a question about exception?

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. public class ExceptionTest {
2. class TestException extends Exception {}
3. public void runTest () throws TestException {}
4. public void test () /* Point X*/ {
5. runTest ();
6. }
7. }
At point X on line 4, which code can be added to make the code compile?
A.throws Exception
B.catch (Exception e)
C.throws RuntimeException
D.catch (TestException e)
E.no code is necessary
Can catch put /*point X*/?why?
 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public class ExceptionTest {
class TestException extends Exception {}
public void runTest () throws TestException {}
public void test () throws Exception {
runTest ();
}
or
public void test () {
try
{
runTest ();
}
catch (Exception e)
{
}
}
}
since u call a method that throws an exception(checked exception), you must throw an exception also in that method(or you should catch the exception in a try/catch stmt)
hope this help
Raymond Yadao
SCJP 1.4
 
Albert Lee
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But the answer is B.so I don't know why?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic