Files
the-way-to-go_ZH_CN/eBook/examples/chapter_13/panic_recover.go
2015-03-03 12:25:25 -05:00

33 lines
454 B
Go

// panic_recover.go
package main
import (
"fmt"
)
func badCall() {
panic("bad end")
}
func test() {
defer func() {
if e := recover(); e != nil {
fmt.Printf("Panicing %s\r\n", e)
}
}()
badCall()
fmt.Printf("After bad call\r\n") // <-- wordt niet bereikt
}
func main() {
fmt.Printf("Calling test\r\n")
test()
fmt.Printf("Test completed\r\n")
}
/* Output:
Calling test
Panicing bad end
Test completed
*/