当前位置:网站首页>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")
}
边栏推荐
- PaddleOCR教程
- ECCV 2022 | 腾讯优图提出DisCo:拯救小模型在自监督学习中的效果
- 【js】-【动态规划】-笔记
- 企业里Win10 开启BitLocker锁定磁盘,如何备份系统,当系统出现问题又如何恢复,快速恢复又兼顾系统安全(远程设备篇)
- Wechat official account solves the cache problem of entering from the customized menu
- Redis:Redis的事务
- LabVIEW中比较两个VI
- 可观测|时序数据降采样在Prometheus实践复盘
- 金融市场,资产管理与投资基金
- MP advanced operation: time operation, SQL, querywapper, lambdaquerywapper (condition constructor) quick filter enumeration class
猜你喜欢
可观测|时序数据降采样在Prometheus实践复盘
Editplus-- usage -- shortcut key / configuration / background color / font size
The small program vant tab component solves the problem of too much text and incomplete display
Redis getting started complete tutorial: hash description
colResizable. JS auto adjust table width plug-in
Why does infographic help your SEO
MariaDB的Galera集群-双主双活安装设置
Etcd database source code analysis - brief process of processing entry records
Redis: redis transactions
JS 3D explosive fragment image switching JS special effect
随机推荐
A mining of edu certificate station
Mit-6.824-lab4b-2022 (10000 word idea explanation - code construction)
ECCV 2022 | 腾讯优图提出DisCo:拯救小模型在自监督学习中的效果
Meet ThreadPoolExecutor
Financial markets, asset management and investment funds
QT personal learning summary
Font design symbol combination multifunctional wechat applet source code
ScriptableObject
45 year old professor, she threw two super unicorns
A complete tutorial for getting started with redis: understanding and using APIs
The solution to the lack of pcntl extension under MAMP, fatal error: call to undefined function pcntl_ signal()
Actual combat simulation │ JWT login authentication
刷题指南-public
D3.js+Three. JS data visualization 3D Earth JS special effect
法国学者:最优传输理论下对抗攻击可解释性探讨
股票账户佣金怎么调低,炒股佣金怎么调低网上开户安全吗
Servlet服务器端和客户端中文输出乱码问题
取得PMP證書需要多長時間?
Ffmpeg quick clip
Paddleocr tutorial