当前位置:网站首页>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")
}
边栏推荐
- Solution record of jamming when using CAD to move bricks in high configuration notebook
- 【taichi】用最少的修改将太极的pbf2d(基于位置的流体模拟)改为pbf3d
- The solution to the lack of pcntl extension under MAMP, fatal error: call to undefined function pcntl_ signal()
- cout/cerr/clog的区别
- 香港珠宝大亨,22亿“抄底”佐丹奴
- MIT-6.824-lab4B-2022(万字思路讲解-代码构建)
- MariaDB's Galera cluster application scenario -- multi master and multi active databases
- How long does it take to obtain a PMP certificate?
- uniapp 除了数字,其他输入无效
- A complete tutorial for getting started with redis: understanding and using APIs
猜你喜欢

LabVIEW中比较两个VI

CTF競賽題解之stm32逆向入門

Blue sky nh55 series notebook memory reading and writing speed is extremely slow, solution process record

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

C language to quickly solve the reverse linked list

Actual combat simulation │ JWT login authentication

Redis introduction complete tutorial: Collection details

Redis:Redis消息的发布与订阅(了解)

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

The difference between debug and release
随机推荐
认识ThreadPoolExecutor
ICML 2022 || 3DLinker: 用于分子链接设计的E(3)等变变分自编码器
Wechat official account solves the cache problem of entering from the customized menu
【监控】zabbix
The initial arrangement of particles in SPH (solved by two pictures)
QT drawing network topology diagram (connecting database, recursive function, infinite drawing, dragging nodes)
Photoshop batch adds different numbers to different pictures
ScriptableObject
[sword finger offer] questions 1-5
头文件重复定义问题解决“C1014错误“
Redis introduction complete tutorial: List explanation
C语言快速解决反转链表
The difference between cout/cerr/clog
CTF competition problem solution STM32 reverse introduction
S32 design studio for arm 2.2 quick start
MIT-6.824-lab4B-2022(万字思路讲解-代码构建)
解决无法通过ssh服务远程连接虚拟机
Jar batch management gadget
Mysql database backup and recovery -- mysqldump command
js正则表达式之中文验证(转)