Are deferred functions called when calling log.Fatalln?
问题 db, err := sql.Open("postgres", "…") if err != nil { log.Fatalln(err) } defer db.Close() tpl, err := template.ParseGlob("") if err != nil { log.Fatalln(err) } If template.ParseGlob("") returns an error, is db.Close() still being called? 回答1: No, the deferred functions aren't run. Here's the description of log.Fatal : Fatal is equivalent to Print() followed by a call to os.Exit(1). log.Fatal calls os.Exit , whose description is here : Exit causes the current program to exit with the given