1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| package main import ( "runtime" "fmt") func main() { outer() }
func outer() { inner() }
func inner() { defer func() { if err := recover(); err != nil { trace := make([]byte, 1024) count := runtime.Stack(trace, true) fmt.Printf("Recover from panic: %s\n", err) fmt.Printf("Stack of %d bytes: %s\n", count, trace) } }()
panic("Fake error!") }
|