当前位置:网站首页>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")
}
边栏推荐
猜你喜欢

机器人强化学习——Learning Synergies between Pushing and Grasping with Self-supervised DRL (2018)

The initial arrangement of particles in SPH (solved by two pictures)

Phpcms paid reading function Alipay payment
![[Jianzhi offer] 6-10 questions](/img/73/5974068008bcdc9a70b3f5f57f1eb0.png)
[Jianzhi offer] 6-10 questions

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

phpcms付费阅读功能支付宝支付

debug和release的区别

香港珠宝大亨,22亿“抄底”佐丹奴

MariaDB's Galera cluster application scenario -- multi master and multi active databases

初试为锐捷交换机跨设备型号升级版本(以RG-S2952G-E为例)
随机推荐
Pict generate orthogonal test cases tutorial
一次edu证书站的挖掘
ICML 2022 || 3DLinker: 用于分子链接设计的E(3)等变变分自编码器
Intelligence test to see idioms guess ancient poems wechat applet source code
[graph theory] topological sorting
HMS core unified scanning service
Tweenmax emoticon button JS special effect
[crawler] XPath for data extraction
Galera cluster of MariaDB - dual active and dual active installation settings
Excel 快捷键-随时补充
Mysql database backup and recovery -- mysqldump command
Object detection based on OpenCV haarcascades
企业里Win10 开启BitLocker锁定磁盘,如何备份系统,当系统出现问题又如何恢复,快速恢复又兼顾系统安全(远程设备篇)
MP advanced operation: time operation, SQL, querywapper, lambdaquerywapper (condition constructor) quick filter enumeration class
A complete tutorial for getting started with redis: redis usage scenarios
Hong Kong Jewelry tycoon, 2.2 billion "bargain hunting" Giordano
Meet ThreadPoolExecutor
Servlet+jdbc+mysql simple web exercise
PMP证书续证流程
French scholars: the explicability of counter attack under optimal transmission theory