Defer call after log.Fatal
I recently learned that when we call log.Fatal
which exist the program using os.Exit
function, any code in defer will not be executed.
Example
- go
1 |
|
This code will print below output:
2009/11/10 23:00:00 fatal error
2009/11/10 23:00:00 Hello, playground
But, if we change line 12 to instead use log.Fatal
then the defer function will not execute.
- go
1 |
|
This code will print below output:
2009/11/10 23:00:00 fatal error