zoukankan      html  css  js  c++  java
  • python 异常处理

     1 import sys
     2 import traceback
     3 
     4 
     5 class MyError(Exception):
     6     def __init__(self, value="this is my test error"):
     7         Exception.__init__(self, value)
     8         # self.value = value
     9 
    10 
    11 def main():
    12     try:
    13         print "this is my exception demo"
    14         raise MyError
    15     except MyError as e:
    16         print e
    17         print sys.exc_info()
    18         print traceback.format_exc()
    19     except Exception as e:
    20         print e
    21         print traceback.format_exc()
    22     else:
    23         print "everything is ok"
    24     finally:
    25         print "It`s always to there"
    26 
    27 if __name__ == '__main__':
    28     main()

    执行结果:

    this is my exception demo

    (<class '__main__.MyError'>, MyError(), <traceback object at 0x02CE7328>)
    Traceback (most recent call last):
    File "***/testException.py", line 14, in main
    raise MyError
    MyError

    It`s always to there

  • 相关阅读:
    win_tc使用感受
    10进制转8进制(栈操作)
    动态栈
    数组
    单链表学习
    static用法
    基础2
    linux c first
    linux net command /uboot command
    opencv
  • 原文地址:https://www.cnblogs.com/huaizhi/p/8479100.html
Copyright © 2011-2022 走看看