python异常
时间:2006-07-07 来源:cnscn2008
[root@localhost python]# cat try.py
#!/usr/bin/python
while True:
try:
x=int(raw_input("Try num: "));
break;
except ValueError:
print "Valid number...";
while True:
x=int(raw_input("No Try num: "));
[root@localhost python]# ./try.py
[注]try
Try num: d
Valid number...
Try num: d
Valid number...
Try num: 3
[注]无try
No Try num: 3
No Try num: 3
No Try num: d
Traceback (most recent call last):
File "./try.py", line 12, in ?
x=int(raw_input("No Try num: "));
ValueError: invalid literal for int(): d
#!/usr/bin/python
while True:
try:
x=int(raw_input("Try num: "));
break;
except ValueError:
print "Valid number...";
while True:
x=int(raw_input("No Try num: "));
[root@localhost python]# ./try.py
[注]try
Try num: d
Valid number...
Try num: d
Valid number...
Try num: 3
[注]无try
No Try num: 3
No Try num: 3
No Try num: d
Traceback (most recent call last):
File "./try.py", line 12, in ?
x=int(raw_input("No Try num: "));
ValueError: invalid literal for int(): d
相关阅读 更多 +