| ???? 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???????
??????????????????????????????????????????????????????????????
| ???? | ????? | ???? |
|---|---|---|
| ???? | ??? | ?????? |