当前位置:网站首页>Instructions for go defer
Instructions for go defer
2022-07-04 23:26:00 【Yard farmer is by my side】
defer yes go A deferred invocation mechanism in ,defer The following functions can only be executed after the current function is executed , Usually used to free up resources .
defer Follow the principle of first in, then out , Similar to the stack structure .
Why do we have to defer Designed into this mechanism ?
Because the resources applied later and may depend on the resources applied earlier . If the previously applied resources are released first . It may have an impact on later resources . So the resources released first and then applied for , Then release the resources previously applied for
func main() {
defer func() {
fmt.Println("w")
if err := recover(); err != nil {
fmt.Println(err)
}
}()
f()
}
func f() {
fmt.Println("a")
panic("error defer")
}
边栏推荐
- [ODX studio edit PDX] - 0.2-how to compare two pdx/odx files of compare
- Explanation of bitwise operators
- HMS core unified scanning service
- QT addition calculator (simple case)
- The initial arrangement of particles in SPH (solved by two pictures)
- 智力考验看成语猜古诗句微信小程序源码
- LIst 相关待整理的知识点
- Application of machine learning in housing price prediction
- Object detection based on OpenCV haarcascades
- Mit-6.824-lab4b-2022 (10000 word idea explanation - code construction)
猜你喜欢
为什么信息图会帮助你的SEO
实战模拟│JWT 登录认证
[Jianzhi offer] 6-10 questions
MIT-6.824-lab4B-2022(万字思路讲解-代码构建)
C language to quickly solve the reverse linked list
MariaDB的Galera集群-双主双活安装设置
SPH中的粒子初始排列问题(两张图解决)
如何报考PMP项目管理认证考试?
D3.js+Three. JS data visualization 3D Earth JS special effect
Redis getting started complete tutorial: Key Management
随机推荐
MP进阶操作: 时间操作, sql,querywapper,lambdaQueryWapper(条件构造器)快速筛选 枚举类
Ffmpeg quick clip
Redis:Redis的事务
A complete tutorial for getting started with redis: understanding and using APIs
Wechat official account solves the cache problem of entering from the customized menu
Solve the problem that the virtual machine cannot be remotely connected through SSH service
ECCV 2022 | 腾讯优图提出DisCo:拯救小模型在自监督学习中的效果
实战模拟│JWT 登录认证
CTF competition problem solution STM32 reverse introduction
D3.js+Three. JS data visualization 3D Earth JS special effect
Object detection based on OpenCV haarcascades
[crawler] jsonpath for data extraction
Redis introduction complete tutorial: detailed explanation of ordered collection
OSEK standard ISO_ 17356 summary introduction
P2181 diagonal and p1030 [noip2001 popularization group] arrange in order
Qt加法计算器(简单案例)
华泰证券低佣金的开户链接安全吗?
Recommended collection: build a cross cloud data warehouse environment, which is particularly dry!
Hong Kong Jewelry tycoon, 2.2 billion "bargain hunting" Giordano
【js】-【动态规划】-笔记