• 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

exception

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
try {
tryThis();
return;
} catch (IOException x1) {
System.out.println("exception 1");
return;
} catch (Exception x2) {
System.out.println("exception 2");
return;
} finally {
System.out.println("finally");
}
What will appear in the standard output if tryThis() throws a
NumberFormatException?
Select the one right answer.
a.Nothing
b."exception 1", followed by "finally"
c."exception 2", followed by "finally"
d."exception 1"
e."exception 2"
can anybody explain how the ans is c
since the NumberFormat Exception is not specified in any of the catch blocks.
thanx
sheri
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An Exception can be caught in a catch statement that is of the same type as the execption throw or is a super class of the excpetion thrown. The full tree for this is

Since Exception is a super class of NumberFormatException it gets caught in the catch (Exception x2).
Hope this helps
 
reply
    Bookmark Topic Watch Topic
  • New Topic