zoukankan      html  css  js  c++  java
  • python异常捕获try except

    python的异常处理机制设计的比较传统,在日常的开发中,基本满足我的需要 

    下面就python的异常,几点小小的讨论 

    tommy@lab3:~$ python
    Python 2.5.2 (r252:60911, Jan 4 2009, 17:40:26)
    [GCC 4.3.2] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 1/0
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    ZeroDivisionError: integer division or modulo by zero
    >>>
    >>> try:
    ... 1/0
    ... except:
    ... print "do something..."
    ...
    do something...
    >>>

    2. try...finally 

    finally 里面只是执行完成try中的代码后,必须执行的代码, 
    即使是 try中有异常抛出,也是会去执行finally 

    >>> try:
    ... 1/0
    ... finally:
    ... print "I just finally do something ,eg: clear!"
    ...
    I just finally do something ,eg: clear!
    Traceback (most recent call last):
    File "<stdin>", line 2, in <module>
    ZeroDivisionError: integer division or modulo by zero
    >>>




  • 相关阅读:
    实习项目1.
    try catch finally的用法
    asp.net 验证控件
    数据库操作语言
    webform Response的一些成员
    jQuery
    C#@的用法
    SQL分页查询
    抽象类与接口的区别
    抽象类与接口
  • 原文地址:https://www.cnblogs.com/wuxi/p/python.html
Copyright © 2011-2022 走看看