By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,237 Members | 1,224 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,237 IT Pros & Developers. It's quick & easy.

How can I make a float throw an exception, when entered?

P: 9
I have a GUI that I use as a calculator. When I enter in anything other than numbers, it throws a NumberFormatException, as intended. But when I enter in a number such as "23423f" the program seems to think I'm entering a float and doesn't throw an exception, because of the f at the end, even though all other letters throw an exception.

Currently, all I'm doing is putting the input section into a try catch block, where I parse it into a double, and having it catch a NumberFormatException if there is one (because only numbers can be parsed into doubles), and another catch block to throw an IllegalArgumentException from an if statement for any input less than 0.

That's just a guess, but I don't know why else only f at the end wouldn't throw an exception.
Feb 23 '12 #1
Share this Question
Share on Google+
1 Reply

P: 13,264
It's not just f.
l at the end makes it a long and d makes it a double.
Feb 23 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.