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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Yii框架官方指南系列52——专题:性能调整

    Yii框架官方指南系列52——专题:性能调整

    2021年8月28日
  • JAVA学习–getInstance「建议收藏」

    JAVA学习–getInstancepublicstaticDBConnectinstance; publicstaticDBConnectgetInstance(){ if(instance==null){  instance=newDBconnect(); } returninstance;…

    2022年4月14日
  • mysql数据库备份方法_oracle数据库备份文件格式

    mysql数据库备份方法_oracle数据库备份文件格式数据库备份Mysqldump:逻辑备份,热备份,全量xtrabackup:物理,热,全量+增量备份一、什么是MySQL主备情况一:客户端的业务操作,读、写访问的是主库主库通过某种机制,将数据实时同步给备库主库由于有些原因,无法正常响应客户端的请求情况二:完成主备切换客户端读写,访问的是备库(此时备库升级为新主库)数据同步是如何实现的?1.主从同步原理1、在备库执行changemaster命令,绑定主库的信息mysql>CHANGEMAS

    2022年11月1日
  • VUE 网页生成 PDF[通俗易懂]

    VUE 网页生成 PDF[通俗易懂]保存当前网页为PDF格式到本地一、安装依赖1.npminstall–savehtml2canvas//作用是html转图片2.npminstalljspdf–save//再将图片转为pdf二、设置格式函数importhtml2Canvasfrom’html2canvas’importJsPDFfrom’jspdf’exportdef…

    2022年5月16日
  • 小爱同学app官方网站(小爱同学唤醒app)

    小爱同学app是一款以连接小爱同学享受人工智能乐趣生活为核心卖点的软件,超多种类的手机都能够使用,无论是苹果亦或是华为小米等,都能够完美的配适,并且还能使用手机唤醒小爱同学,帮它联网,教他各种不同的知识,之后还能和你愉快的聊天!小爱同学app特色听听音乐,看看各种笑话,休闲无比放松逗小爱,即时你是孤身一人也不再会孤单!远程操控你的各种智能设备,远距离控制不再是问题,解决所有的难题!自带语音识别的功…

    2022年4月10日
  • Java爬取先知论坛文章

    Java爬取先知论坛文章0x00前言上篇文章写了部分爬虫代码,这里给出一个完整的爬取先知论坛文章代码,用于技术交流。0x01代码实现pom.xml加入依赖:<dependencie

    2021年12月12日

发表回复

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

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