栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

云学编程的第8天—【微软官方python入门教程 P17-P18笔记】2021-11-08 错误类型

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

云学编程的第8天—【微软官方python入门教程 P17-P18笔记】2021-11-08 错误类型

P17Error handling​​​​​​​

 

`Error handling is when I have a problem with my code that's running, and it's not something that I'm going to be able to predict when I pushed my code out to production.

permissions issue; a database changing; a server being down etc

`Debugging is when I know that there's problem with my code.It's potentially crashing. 

Error types : Syntax errors; Runtime errors; Logic errors.

With syntax errors, a code is not going to run at all. This is typically going to be the easiest to try and track down.

Runtime erros,also,they will give you a little bit of imformation right upfront. the basic strategy here is to start from the line that it's given you.

Catching runtime errors,try/except/finally

Logic errors : everything run, but we just don't get the right responde. I frequenly reverse my boolean. Little side note here, i would definitely recommend taking a look at unit testing and test-driven develpment.

Figuring out what went wrong:1. Stack trace: (1)Last calls are on the top;(2) Your code is likely on the bottom; (3)Seek out line numbers. 2.Finding your mistake: (1)Reread your code ;(2) Check the documentation;(3) Search the internet ; (4)Take a break ;(5)Ask others for help.

P18实操

x=42
y=0

print()
try:
    print(x/y)
except ZeroDivisionError as e:
    print('division by zero')
else:
    print('Something else went wrong')
finally:
    print('This is our cleanup code')
print()

division by zero
This is our cleanup code

导师语录

try里面就是放 你想执行什么代码;catch就是 运行代码可能会出错 你就把它捕获住;finally里面的代码表示不管有没有错之后都执行;比如说代码出错了 但是你想继续执行 你就可以在except里面做一些操作记录一下 然后继续执行;要是不加的话程序就崩溃了;简单一个来讲就是一个是有备案的 一个是顶风作案 逮住枪毙我找对了try里面的错,Except就会执行了

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/460968.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号