Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

exception handling ??

 
srikanth reddy
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following method is designed to convert an input string to a
floating point number while detecting a bad format.
[3] [I think factor must have been declared as float member variable
or something]

Which of the following descriptions of the results of various inputs to the method are correct?
(a)Input = �0.234� � Result: factor = 0.234, �Finally� is printed, true is returned.
(b)Input = �0.234� � Result: factor = 0.234, �Finally� is printed, false is returned.
(c)Input = null � Result: factor = NaN, �Finally� is printed, false is returned.
(d)Input = null � Result: factor = unchanged, �Finally� is printed, NullPointerException is thrown.


frnds ,
option a is correct ..that is fine ...i cannot understand why opition is correct ...specifically factor = unchanged i didnt get

can anyone clarify it

sri
[ October 13, 2005: Message edited by: Barry Gaunt ]
 
Sandeep Chhabra
Ranch Hand
Posts: 340
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by srikanth reddy:



(d)Input = null � Result: factor = unchanged, �Finally� is printed, NullPointerException is thrown.



Its simple
factor = Float.valueOf(s).floatValue();
In this statement the exception occurs while performing Float.valueOf(s) ie. before calculating .floatValue() and before assigning the calculated value to the variable factor. As soon as the exception occurs control jumps to the corresponding exception handler withoug assigning anything to factor.
hence factor remain unchanged.

Hope it helps
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic