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

掌握错误处理:代码调试与异常捕获实战
本文讲解了错误处理在软件开发中的重要性,区分了错误类型如语法错误、运行时错误和逻辑错误,并提供了调试和使用try-except-finally语句处理异常的技巧。通过实例演示了如何在代码中捕捉并处理可能出现的问题,以及导师分享的实用建议。

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就会执行了

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值