Given a string from user input, I want to convert it to a
if the string is a valid int. I do not want to convert to an int if the string is a float. If that fails, I then want to try to convert the string to a
. If the string is not either of these I intend to just raise an exception.
It seems that
just truncates any
value rather than providing any sort of error. I know I could do some regexing to determine whether a
is a valid int, but it seems like there should be some built-in conversion that fails if a
has anything other that digits. Am I missing something?
For example. I want something like this that fails instead of returning