| ???? Python ??? | ??13?? ?? | |
|---|---|---|
| ???? | try..except | ???? |
?????????????????????????Ctrl-d??????????????
>>> s = raw_input('Enter something --> ')
Enter something --> Traceback (most recent call last):
File "<stdin>", line 1, in ?
EOFError
Python????????????EOFError???????????????????¦Æ??????????????????? ???¦Â ????Ctrl-d?????
?????????????????¦Ä????????????
??????????try..except?????????????????????????????try-???§µ?????????????????????except-???§³?
#!/usr/bin/python
# Filename: try_except.py
import sys
try:
s = raw_input('Enter something --> ')
except EOFError:
print '\nWhy did you do an EOF on me?'
sys.exit() # exit the program
except:
print '\nSome error/exception occurred.'
# here, we are not exiting the program
print 'Done'
????????code/try_except.py??
$ python try_except.py
Enter something -->
Why did you do an EOF on me?
$ python try_except.py
Enter something --> Python is exceptional!
Done
????????§á??????????????????try???§µ??????except???/???§Õ??????§Ö?????????except???????????????????????????????????????????????/?????????§Ú??????????????????????? ???§Ö? ????????????????try????????????????????except???
???????????????§Ò??????????Python????????????¨¢????????????????§µ??????????????????????????????????????
????????try..catch??????????else???????????????????else??�Þ????§³?
????????????????????????????§Ú??????????????????????????????????
| ???? | ????? | ???? |
|---|---|---|
| ???? | ??? | ?????? |