当前位置:网站首页>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")
}
边栏推荐
- 金融市场,资产管理与投资基金
- 【监控】zabbix
- MP进阶操作: 时间操作, sql,querywapper,lambdaQueryWapper(条件构造器)快速筛选 枚举类
- Paddleocr tutorial
- 高通WLAN框架学习(30)-- 支持双STA的组件
- 头文件重复定义问题解决“C1014错误“
- Question brushing guide public
- The input of uniapp is invalid except for numbers
- Etcd database source code analysis - brief process of processing entry records
- How long does it take to obtain a PMP certificate?
猜你喜欢

Redis introduction complete tutorial: List explanation

Why does infographic help your SEO

MariaDB的Galera集群应用场景--数据库多主多活

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

debug和release的区别

Intelligence test to see idioms guess ancient poems wechat applet source code

The caching feature of docker image and dockerfile

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

Redis:Redis的事务

CTF competition problem solution STM32 reverse introduction
随机推荐
How to reduce the stock account Commission and stock speculation commission? Is it safe to open an online account
Redis: redis message publishing and subscription (understand)
Excel shortcut keys - always add
How to choose a securities company? Is it safe to open an account on your mobile phone
LIst 相关待整理的知识点
qt绘制网络拓补图(连接数据库,递归函数,无限绘制,可拖动节点)
Excel 快捷键-随时补充
数据库基础知识
Basic use and upgrade of Android native database
一次edu证书站的挖掘
The initial arrangement of particles in SPH (solved by two pictures)
MP advanced operation: time operation, SQL, querywapper, lambdaquerywapper (condition constructor) quick filter enumeration class
colResizable. JS auto adjust table width plug-in
高通WLAN框架学习(30)-- 支持双STA的组件
CTF競賽題解之stm32逆向入門
debug和release的区别
Redis:Redis的事务
[crawler] XPath for data extraction
Hong Kong Jewelry tycoon, 2.2 billion "bargain hunting" Giordano
Jar批量管理小工具