very newbie question about exception handling

Louis.Soninhu at gmail.com Louis.Soninhu at gmail.com
Mon Dec 24 17:16:35 EST 2007


code sample:
----------------------------------------------
i=input()
try:
    x=int(i)
    print "you input an integer"
except ValueError:
    print "you must input an integer"
------------------------------------------------
when I input a value like, b
I got the traceback message instead of proper exception handling:

NameError: b is not defined

I also tried
------------------------------------------
try: x=int(i)
except ValueError: print "something"
except NameError: pting "something"
else: print "something"
----------------------------------------------------
It still couldn't capture the exception, just the same traceback error
msg.

I'm really confused, any suggestions please?




More information about the Python-list mailing list