• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Exception

 
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Skillfox discussion forum question


What will appear in the standard output if tryThis() throws a NumberFormatException?
a. Nothing
b. "exception 1", followed by "finally"
c. "exception 2", followed by "finally"
d. "exception 1"
e. "exception 2"

The answer they have given is c.But when i execute the program ,i got the error at line 1 telling
IOException is never thrwon in try block.Please clarify
 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are correct ShivMohan!!!
Some mock exams confuse us; Very bad;


NumberFormatException(unchecked exception) IS-A IllegalArgumentException IS-A RuntimeException;



IOException extends Exception and is checked exception;
If you catch the IOException (checked exception), the try
block must throw that exception otherwise compilation error.



In your question tryThis() throws NumberFormatException, so
compiler recognizes this and gives error;

Confirm this!!!

Regards,
cmbhatt
 
Shiva Mohan
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply Chandra.Yes the question asked that tryThis() throws NumberFormatException.

So if the checkedException is caught or declared in the method,we must throw it in try block.Am i correct
[ April 20, 2007: Message edited by: Shiva Mohan ]
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


ShivMohan says,
So if the checkedException is caught or declared in the method,we must throw it in try block.Am i correct



Nay,
In case you declare the checked exception in the method, you need not to throw it in that, you mean by declaring that you are ducking the exception.


In case of try catch case , you are correct.


No problem with this code!!!

Regards,
cmbhatt
[ April 20, 2007: Message edited by: Chandra Bhatt ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic