Python handling an exception「建议收藏」

Python handling an exception

大家好,又见面了,我是全栈君。

#try...except...
try:
   You do your operations here;
   ......................
except ExceptionI:
   If there is ExceptionI, then execute this block.
except ExceptionII:
   If there is ExceptionII, then execute this block.
   ......................
else:
   If there is no exception then execute this block. 

#The except Clause with No Exceptions
try:
   You do your operations here;
   ......................
except:
   If there is any exception, then execute this block.
   ......................
else:
   If there is no exception then execute this block. 

#The except Clause with Multiple Exceptions
try:
   You do your operations here;
   ......................
except(Exception1[, Exception2[,...ExceptionN]]]):
   If there is any exception from the given exception list, 
   then execute this block.
   ......................
else:
   If there is no exception then execute this block. 

#The try-finally Clause
try:
   You do your operations here;
   ......................
   Due to any exception, this may be skipped.
finally:
   This would always be executed.
   ......................

#Argument of an Exception
try:
   You do your operations here;
   ......................
except ExceptionType, Argument:
   You can print value of Argument here...

  

转载于:https://www.cnblogs.com/KennyRom/p/6294536.html

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/108689.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • markdown字体颜色设置_markdown红色字体

    markdown字体颜色设置_markdown红色字体 Markdown是一种可以使用普通文本编辑器编写的标记语言,通过类似HTML的标记语法,它可以使普通文本内容具有一定的格式。但是它本身是不支持修改背景色功能的!  从HTMLEditor转到CSDN-markdown编辑器的很多朋友可能有些不适应,明明很简单的背景色功能,这里却找不到了。  CSDN-markdown编辑器是其衍生版本,扩展了Markdown的功能(如表格、脚注、内嵌HTML等等)!对,就是内嵌HTML,接下来要讲的功能就需要使用内嵌HTML的方法来实现。  背景色由.

    2022年10月22日
    0
  • 解决gradle下载慢的问题

    解决gradle下载慢的问题开发工具:IntelliJIDEA&AndroidStudio问题:新建项目下载gradle慢的问题解决:打开用户主目录linux平台/home/用户名/.gradlewindows平台c:\Users\用户名\.gradlemacos平台/Users/用户名/.gradle找到./gradle/wrapper/dist/gradle-版本号-bin目

    2022年6月16日
    28
  • Latex希腊字母、特殊符号汇总表

    Latex希腊字母、特殊符号汇总表Latex和Matlab绘图中希腊字母、特殊符号汇总表Latex和Matlab绘图中希腊字母、特殊符号汇总表Latex和Matlab绘图中希腊字母、特殊符号汇总表一、小写希腊字母、特殊符号二、大写希腊字母三、希腊字母斜体原创不易,路过的各位大佬请点个赞一、小写希腊字母、特殊符号二、大写希腊字母三、希腊字母斜体原创不易,路过的各位大佬请点个赞…

    2022年10月25日
    0
  • 网络视频教程(共57个)全实战过程

    网络视频教程(共57个)全实战过程01ping命令的使用http://images.enet.com.cn/eschool/wmv/ping.wmv02netstat命令的使用http://images.enet.com.cn/eschool/wmv/netstat.wmv03tasklist和taskkill的使用http://images.enet.com.cn/eschool/wmv/tasklist.wmv0

    2022年6月14日
    28
  • String,StringBuffer和StringBuilder的区别及使用场景[通俗易懂]

    String,StringBuffer和StringBuilder的区别及使用场景[通俗易懂]String:字符串常量。StringBuffer与StringBuilder是字符缓冲变量。StringBuffer与StringBuilder中的方法和功能完全是等价的,只是StringBuffer中的方法大都采用了synchronized关键字进行修饰,因此是线程安全的,而StringBuilder没有这个修饰,可以被认为是线程不安全的。StringBuilder是在…

    2022年9月21日
    0
  • windows修改dns服务器,windowns中dns服务器配置与管理详解(多图)

    windows修改dns服务器,windowns中dns服务器配置与管理详解(多图)安装DNS服务器在”服务器管理器”-“角色”-“添加角色”中安装DNS服务器。选择DNS服务器点下一步安装,然后安装固定服务器IP地址安装完DNS和配置好固定ip后,我们就可以开始配置DNS。在”开始”-“管理工具”-DNS打开DNS正向区域的建立并为其设置主机。选择”正向查找区域”-右击-新建区域。填写域名之后全部默认设置,直至完成。域名建立之后,我们就可以为其”新建主机”选择”hzu.com”…

    2022年6月3日
    122

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号