You second example isn't calling recover inside the defer.
See: https://golang.org/pkg/builtin/#recover
On 28/03/2017 23:00, Stefan Engstrom wrote:
Playing with recovery from a panic - this code does what i expect:
(https://play.golang.org/p/p5KvOYc1sx)
|
packagemain
import"fmt"
func main(){
Playing with recovery from a panic - this code does what i expect: (
https://play.golang.org/p/p5KvOYc1sx)
package main
import "fmt"
func main() {
defer func() {
fmt.Println("main:",recover())
}()
a()
}
func a() {
panic("yikes")
}
Results in:
main: yikes
A simpler version with