python错误捕获练习

Posted 一株草

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python错误捕获练习相关的知识,希望对你有一定的参考价值。

一:错误捕获联系例子

#codeing=utf-8
def test_index(string,index):
    print string[index];

str="thiistest";
num=3;
try:#尝试运行
    test_index(str,num);
except IndexError:#except后面跟随错误类型
    print "索引类型错误";    
except TypeError as s: #python语法错误赋值给s在错判断
    
else:
    print "没有错误发生";    
finally:
    print "不管有没有错误都会走";

 

以上是关于python错误捕获练习的主要内容,如果未能解决你的问题,请参考以下文章

php try catch 捕获哪些错误

代码片段 PHP,预期文件结尾,我错在哪里?

PHP代码-psysh调试代码片段工具

php中的错误异常处理

PHP MySQL 事务捕获错误

更好的PHP错误处理