当前位置:网站首页>Learn this trick and never be afraid to let the code collapse by mistake
Learn this trick and never be afraid to let the code collapse by mistake
2022-07-28 02:26:00 【51CTO】
Reading guide
I learned a very interesting move today , Ride the hot iron to share a wave !
More specifically, it is about python Application of exception handling , Realize a function that you can be forgiven for wrong hand input , It's very easy to use and interesting >_<

One 、 Exception and exception handling
In order to have a clearer understanding of what needs to be done next , We need to understand a few concepts first .
First of all , What is an anomaly . An exception is an event , This event occurs during program execution , It affects the normal execution of the program .
An inappropriate metaphor is , When you are picking up girls , Suddenly a silly Eagle came and said you had bad breath , Always fart , It directly makes you unable to pick up girls normally .
second , What exception handling , In order to solve when an exception occurs , We don't want our program to hang up , And some operations .
And exception handling is similar to when you know this unlucky guy is coming , There must be no good words , You predicted in advance that it would happen , Backhand is to slap him , Then let him talk well , In the end, things are going in a good direction .
Two 、 Small application of exception handling
We often encounter, for example, the need to enter a password , When you enter the wrong password , You don't want to quit the system , Instead, re-enter the password ; Or to read a picture , But sometimes the hand hits the wrong path by mistake , You don't want the whole code to run again , In order for the code to recognize your mistakes and allow you to re-enter , Until you finally enter the path correctly .
In this case , Wrong address , The code stops directly , It's not what we want
How can we solve it ?
Ideas :
(1) Find out what may go wrong , Make detection and judgment ;
(2) When the input is correct , Go directly to the next step ;
(3) When the input is wrong , Re execution , Until it's right .
Complete code : https://github.com/DWCTOD/AI_study/blob/master/06-yichangchuli
3、 ... and 、 Effect display
Use the screen recording software provided by the system to operate it again , Let everyone see more clearly :

It's hard , I don't know why there is a problem with the displayed picture , This screen recording software is poisonous , It's OK to see it on your computer !!! Study it later .
Here is just a simple demonstration of an interesting function , For exception handling , I didn't learn deeply enough , If you get a chance later , Continue to study !


边栏推荐
- 微信小程序实现动态横向步骤条的两种方式
- pytorch优化器设置
- 【网站搭建】使用acme.sh更新ssl证书:将zerossl改为letsencrypt
- Plato Farm在Elephant Swap上铸造的ePLATO是什么?
- Promise from getting started to mastering (Chapter 3: customize (handwriting) promise)
- 小米网站主页面大模块——小模块+导航(浮动案例)
- Unittest单元测试框架全栈知识
- Flex development web page instance web side
- 使用BigDecimal类型应该避免哪些问题?(荣耀典藏版)
- 实际工作中,我是如何使用 Postman 做接口测试?
猜你喜欢
![[advanced ROS] Lecture 9 robot model motion based on rviz and arbotix control](/img/7f/f0360210e8a9f7e45410d79635bfd9.png)
[advanced ROS] Lecture 9 robot model motion based on rviz and arbotix control

产品解读丨MeterSphere UI测试模块的设计与分布式扩展

Flex development web page instance web side

MySQL explain (glory Collection Edition)

Go learn 02 basic knowledge

Structure pseudo class selector - find single - find multiple - nth of type and pseudo elements

微信小程序实现动态横向步骤条的两种方式

54: Chapter 5: develop admin management services: 7: face warehousing process; Face login process; The browser turns on the video debugging mode (so that the camera can also be turned on in the case o

Aike AI frontier promotion (7.14)

Codeworks round 807 (Div. 2) a-c problem solution
随机推荐
MySQL high availability and master-slave synchronization
Principle and implementation of cross entropy
Two ways for wechat applet to realize dynamic horizontal step bar
获取两个集合相差数据
小程序毕设作品之微信校园浴室预约小程序毕业设计成品(1)开发概要
synchronized详解
小程序毕设作品之微信校园浴室预约小程序毕业设计成品(3)后台功能
QGIS mapping: vector data mapping process and export
【Star项目】小帽飞机大战(六)
Flex development web page instance web side
MySQL explain (glory Collection Edition)
[机缘参悟-53]:阳谋立身,阴谋防身
Flume(5个demo轻松入门)
Shell regular and metacharacters
CeresDAO:全球首个基于DAO赋能Web3.0的去中心化数字资产管理协议
【ROS进阶篇】第九讲 基于Rviz和Arbotix控制的机器人模型运动
Important arrangements - the follow-up live broadcast of dx12 engine development course will be held at station B
[advanced ROS] Lecture 9 robot model motion based on rviz and arbotix control
mysql创建存储过程---------[HY000][1418] This function has none of DETERMINISTIC, NO SQL
Flex开发网页实例web端