<dd id="sga4y"><optgroup id="sga4y"></optgroup></dd>
<nav id="sga4y"><code id="sga4y"></code></nav>
  • <optgroup id="sga4y"></optgroup>
    ???? Python ???
    ??13?? ??
    ???? try..except ????

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

    ??13.1 ??????

    #!/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???????

    ??????????????????????????????????????????????????????????????


    ???? ????? ????
    ???? ??? ??????
    ?????
    @ssv 97av