zoukankan      html  css  js  c++  java
  • 《Python 第八章》异常

    第 8 章 异常
    >>> raise Exception("hello") 引发异常 raise 异常类/异常实例
    >>> import exceptions
    Exception 是所有异常的基类
    @学习摘录 801:自定义异常类
     —— class SomeCustomException(Exception) : pass
    @学习摘录 802:捕获异常
     try :
         x = input("x : ")
         y = input('y : ') 
         print x / y
     except ZeroDivisionError :
         print "The second num can't zero!"
     except TypeError :
         print "That wasn't a number."
       用一个块捕捉两个异常
     try :
         x = input("x : ")
         y = input('y : ') 
         print x / y
     except (ZeroDivisionError, TypeError), e :
         print e
     except : 这样子写的话,就是捕捉所有异常了,不推荐!
    @学习摘录 803:万事大吉
         try
         except :
         else :
         finally : 最后
       异常上浮-主程序-堆栈跟踪,最后!
    

  • 相关阅读:
    k8s蓝绿
    nginx总结
    promethues监控 之 TCP连接数
    制作私有ssl证书
    redis命令
    zabbix主机自动发现
    Kubernetes各组件服务重启
    linxu下常用命令
    encodeURIComponent
    查询条件
  • 原文地址:https://www.cnblogs.com/robbychan/p/3787024.html
Copyright © 2011-2022 走看看