当前位置:网站首页>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")
}
边栏推荐
- MariaDB的Galera集群应用场景--数据库多主多活
- Docker镜像的缓存特性和Dockerfile
- How to choose a securities company? Is it safe to open an account on your mobile phone
- Font design symbol combination multifunctional wechat applet source code
- The initial trial is the cross device model upgrade version of Ruijie switch (taking rg-s2952g-e as an example)
- 机器人强化学习——Learning Synergies between Pushing and Grasping with Self-supervised DRL (2018)
- 如何报考PMP项目管理认证考试?
- 法国学者:最优传输理论下对抗攻击可解释性探讨
- [crawler] jsonpath for data extraction
- CTF竞赛题解之stm32逆向入门
猜你喜欢
SPH中的粒子初始排列问题(两张图解决)
Editplus-- usage -- shortcut key / configuration / background color / font size
Hong Kong Jewelry tycoon, 2.2 billion "bargain hunting" Giordano
ETCD数据库源码分析——处理Entry记录简要流程
Redis: redis transactions
The difference between debug and release
Galera cluster of MariaDB - dual active and dual active installation settings
如何报考PMP项目管理认证考试?
Explanation of bitwise operators
Font design symbol combination multifunctional wechat applet source code
随机推荐
CTF竞赛题解之stm32逆向入门
How long does it take to obtain a PMP certificate?
[JS] - [dynamic planning] - Notes
Financial markets, asset management and investment funds
JS card style countdown days
【爬虫】数据提取之JSONpath
ECS settings SSH key login
解决无法通过ssh服务远程连接虚拟机
PMP证书续证流程
QT drawing network topology diagram (connecting database, recursive function, infinite drawing, dragging nodes)
45 year old professor, she threw two super unicorns
ECCV 2022 | 腾讯优图提出DisCo:拯救小模型在自监督学习中的效果
Paddleocr tutorial
【js】-【动态规划】-笔记
MySQL数据库备份与恢复--mysqldump命令
QT addition calculator (simple case)
Servlet+JDBC+MySQL简单web练习
Question brushing guide public
How to choose a securities company? Is it safe to open an account on your mobile phone
数据库基础知识