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

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

云学编程的第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里面做一些 *** 作记录一下 然后继续执行;要是不加的话程序就崩溃了;简单一个来讲就是一个是有备案的 一个是顶风作案 逮住q毙我找对了try里面的错,Except就会执行了

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5436476.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-11
下一篇 2022-12-11

发表评论

登录后才能评论

评论列表(0条)

保存