What are the differences in outcome for panic vs log.Fatalln()?

  • The log message goes to the configured log output, while panic is only going to write to stderr.

  • Panic will print a stack trace, which may not be relevant to the error at all.

  • Defers will be executed when a program panics, but calling os.Exit exits immediately, and deferred functions can’t be run.

In general, only use panic for programming errors, where the stack trace is important to the context of the error. If the message isn’t targeted at the programmer, you’re simply hiding the message in superfluous data.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)