Python try except

后端 未结 5 1563
[愿得一人]
[愿得一人] 2021-01-19 00:12
try:
    #statement 1
    #statement 2
except Exception, err:
    print err
    pass

This may be very trivial but I never actually thought about it

5条回答
  •  时光取名叫无心
    2021-01-19 00:56

    The answer is "no" to both of your questions.

    As soon as an error is thrown in a try/except block, the try part is immediately exited:

    >>> try:
    ...     1/0
    ...     print 'hi'
    ... except ZeroDivisionError, e:
    ...     print 'error'
    ...
    error
    >>>
    

    As you can see, the code never gets to the print 'hi' part, even though I made an except for it.

    You can read more here.

提交回复
热议问题