This week's book giveaway is in the Kotlin forum.We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering Languages Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# exception handling ??

srikanth reddy
Ranch Hand
Posts: 252
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
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