This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
Generally, exceptions should be thrown only for unexpected conditions, those that you can't foresee and control through your code. It would be better if you can avoid to throw an exception by using some sort of validation (an if-else for example).
For educative purposes and to answer your question, a simple way to throw an exception for a "wrong" input String would be (in pseudocode):
if String contains alphabetical characters, then throw Exception (IllegalArgumentException would be a good candidate in our case);
I agree. But regardless of whether you use exceptions or not, the first step is to define what EXACTLY is and is not allowed. What about symbols? What about commas, decimal points, negative signs? In accounting practices, I believe parentheses are acceptable to indicate a negative value.
And don't forget that different locations in the world use the '.' and the ',' in the exact opposite manner...
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
I would create a validation method that accepted an input String and returned true/false if it was valid or not. As others have suggested, check for all possible input characters. Is white space allowed (space, tab)? How big can the input string be? If it represents an integer, you can use Integer.parseInt(String s) to see if it is valid. This method will throw a NumberFormatException if it cannot parse the String as an int.