How about having x be a string (instead of an int) then try to parse it into an int? If it doesn't parse it should go to the catch.
EDIT: by x I mean the number you're inputting.
My Anime List
BattleTag (EU): razaron#1882