Skip to content

Instantly share code, notes, and snippets.

@rhcarvalho
Created March 31, 2016 08:57
Show Gist options
  • Save rhcarvalho/689ebc47aa39fd7069904e325ae43e06 to your computer and use it in GitHub Desktop.
Save rhcarvalho/689ebc47aa39fd7069904e325ae43e06 to your computer and use it in GitHub Desktop.
Go executes deferred calls on panic
$ go run signal.go
1/3 = 0
1/2 = 0
1/1 = 1
hello from deferred call!
panic: runtime error: integer divide by zero
[signal 0x8 code=0x1 addr=0x400d3d pc=0x400d3d]
goroutine 1 [running]:
main.main()
/tmp/signal.go:10 +0x13d
exit status 2
package main
import (
"fmt"
)
func main() {
defer fmt.Println("hello from deferred call!")
for i := 3; i >= 0; i-- {
fmt.Printf("1/%v = %v\n", i, 1/i)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment