panic: Panic from user
goroutine 1 [running]:
main.causedPanic()
/tmp/sandbox078566511/main.go:11 +0x60
main.run()
/tmp/sandbox078566511/main.go:7 +0x20
main.main()
/tmp/sandbox078566511/main.go:4 +0x20
panic: runtime error: invalid memory address or nil pointer dereference
goroutine 1 [running]:
main.main()
/tmp/sandbox277759147/main.go:4 +0x4
If I add a defer to the last function, the stack comes back, code is https://play.golang.org/p/V7qDdyt_4Z , output is:
panic: runtime error: invalid memory address or nil pointer dereference
goroutine 1 [running]:
main.causedPanic()
/tmp/sandbox416089181/main.go:13 +0x48
main.run()
/tmp/sandbox416089181/main.go:7 +0x20
main.main()
/tmp/sandbox416089181/main.go:4 +0x20
Why it's diferent when there is a empty defer? It confused me.
winlin$ go run -gcflags="-l" t.go
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x104bf82]
goroutine 1 [running]:
main.causedPanic()
/Users/winlin/git/t.go:13 +0x2
main.run()
/Users/winlin/git/t.go:7 +0x20
main.main()
/Users/winlin/git/t.go:4 +0x20
exit status 2