try/except block that checks for correct user input : except « Statement « Python Tutorial






try:
    x = raw_input("Enter an integer: ")
    y = int(x)
    print "Your number was", y
except (TypeError, ValueError):
    print "That didn't look like an integer to me."








3.10.except
3.10.1.Catching Two Exceptions
3.10.2.Simple exception handling example.
3.10.3.Demonstrating exception arguments and stack unwinding.
3.10.4.Catch more than on exceptions
3.10.5.Catch KeyError and AssertionError
3.10.6.try/except block that checks for correct user input
3.10.7.try/except block with string argument