• 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
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic