I have a method that accepts a String argument.
The String could contain an integer, long, double, boolean, or just plain old characters and numbers.
I need an easy way to determine which type the string has.
One way could be to have a bunch of try catch blocks and try to parse it into each types, and if an exception is thrown, then it is probably not that data type. That seems wrong because it’s a heuristic, not a deterministic program.
If you know what the type should be once you know the parameter, then parsing the string to that type and catching an exception is OK – it’s an appropriate use of exceptions to catch invalid data (as long as you’re only trying one type…)