Hacker News new | past | comments | ask | show | jobs | submit login

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`





Consider applying for YC's Summer 2025 batch! Applications are open till May 13

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: