Created
August 25, 2015 13:44
-
-
Save lvidarte/923b3b11bfc6ac180387 to your computer and use it in GitHub Desktop.
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() { | |
f() | |
fmt.Println("Returned normally from f.") | |
} | |
func f() { | |
defer func() { | |
if r := recover(); r != nil { | |
fmt.Println("Recovered in f", r) | |
} | |
}() | |
fmt.Println("Calling g.") | |
g(0) | |
fmt.Println("Returned normally from g.") | |
} | |
func g(i int) { | |
if i > 3 { | |
fmt.Println("Panicking!") | |
panic(fmt.Sprintf("%v", i)) | |
} | |
defer fmt.Println("Defer in g", i) | |
fmt.Println("Printing in g", i) | |
g(i + 1) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment