2 ms·
one tiny thing I see quite often: people think that if you do `log.Fatal`, it will still run things in `defer`. It won't! package main import (
by karel-3d 1y ago
one tiny thing I see quite often: people think that if you do `log.Fatal`, it will still run things in `defer`. It won't!
package main
import (
"fmt"
"log"
)
func main() {
defer fmt.Println("in defer")
log.Fatal("fatal")
}
this just runs "fatal"... because log.Fatal calls os.Exit, and that closes everything immediately.
package main
import (
"fmt"
"log"
)
func main() {
defer fmt.Println("in defer")
panic("fatal")
}
This shows both `fatal` and `in defer`