Created
March 31, 2016 08:57
-
-
Save rhcarvalho/689ebc47aa39fd7069904e325ae43e06 to your computer and use it in GitHub Desktop.
Go executes deferred calls on panic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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