当前位置:网站首页>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")
}
边栏推荐
- Wechat official account solves the cache problem of entering from the customized menu
- Meet ThreadPoolExecutor
- [JS] - [sort related] - Notes
- ffmpeg快速剪辑
- Redis getting started complete tutorial: Key Management
- ScriptableObject
- 45 year old professor, she threw two super unicorns
- 金融市场,资产管理与投资基金
- The difference between debug and release
- Header file duplicate definition problem solving "c1014 error“
猜你喜欢

高通WLAN框架学习(30)-- 支持双STA的组件

高配笔记本使用CAD搬砖时卡死解决记录

uniapp 除了数字,其他输入无效

QT drawing network topology diagram (connecting database, recursive function, infinite drawing, dragging nodes)

ICML 2022 || 3DLinker: 用于分子链接设计的E(3)等变变分自编码器

45岁教授,她投出2个超级独角兽

Hong Kong Jewelry tycoon, 2.2 billion "bargain hunting" Giordano

Redis getting started complete tutorial: Key Management

【二叉树】节点与其祖先之间的最大差值

debug和release的区别
随机推荐
Basic use and upgrade of Android native database
[JS] - [dynamic planning] - Notes
How to apply for PMP project management certification examination?
Mysql database backup and recovery -- mysqldump command
D3.js+Three. JS data visualization 3D Earth JS special effect
[Jianzhi offer] 6-10 questions
SPH中的粒子初始排列问题(两张图解决)
The Chinese output of servlet server and client is garbled
js正则表达式之中文验证(转)
HMS core machine learning service
Is the account opening link of Huatai Securities with low commission safe?
Pict generate orthogonal test cases tutorial
Basic knowledge of database
刷题指南-public
解决无法通过ssh服务远程连接虚拟机
企业里Win10 开启BitLocker锁定磁盘,如何备份系统,当系统出现问题又如何恢复,快速恢复又兼顾系统安全(远程设备篇)
CTF competition problem solution STM32 reverse introduction
数据库基础知识
45 year old professor, she threw two super unicorns
高通WLAN框架学习(30)-- 支持双STA的组件