当前位置:网站首页>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")
}
边栏推荐
- Jar批量管理小工具
- UML diagram memory skills
- The input of uniapp is invalid except for numbers
- Explanation of bitwise operators
- debug和release的区别
- ICML 2022 || 3DLinker: 用于分子链接设计的E(3)等变变分自编码器
- Photoshop batch adds different numbers to different pictures
- 【爬虫】数据提取之xpath
- The small program vant tab component solves the problem of too much text and incomplete display
- 实战模拟│JWT 登录认证
猜你喜欢
[JS] - [sort related] - Notes
S32 Design Studio for ARM 2.2 快速入门
CTF競賽題解之stm32逆向入門
可观测|时序数据降采样在Prometheus实践复盘
高通WLAN框架学习(30)-- 支持双STA的组件
Redis: redis message publishing and subscription (understand)
壁仞科技研究院前沿技术文章精选
取得PMP证书需要多长时间?
Galera cluster of MariaDB - dual active and dual active installation settings
ECCV 2022 | Tencent Youtu proposed disco: the effect of saving small models in self supervised learning
随机推荐
股票账户佣金怎么调低,炒股佣金怎么调低网上开户安全吗
Docker镜像的缓存特性和Dockerfile
The initial trial is the cross device model upgrade version of Ruijie switch (taking rg-s2952g-e as an example)
JS 3D explosive fragment image switching JS special effect
Etcd database source code analysis - brief process of processing entry records
Meet ThreadPoolExecutor
MP advanced operation: time operation, SQL, querywapper, lambdaquerywapper (condition constructor) quick filter enumeration class
Qt个人学习总结
[graph theory] topological sorting
ECCV 2022 | 腾讯优图提出DisCo:拯救小模型在自监督学习中的效果
The initial arrangement of particles in SPH (solved by two pictures)
Selected cutting-edge technical articles of Bi Ren Academy of science and technology
Redis introduction complete tutorial: detailed explanation of ordered collection
Header file duplicate definition problem solving "c1014 error“
A complete tutorial for getting started with redis: understanding and using APIs
[ODX studio edit PDX] - 0.2-how to compare two pdx/odx files of compare
P2181 diagonal and p1030 [noip2001 popularization group] arrange in order
LabVIEW中比较两个VI
Redis: redis message publishing and subscription (understand)
【kotlin】第三天