panic 和 recover

panic 和 recover

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
package main

import "fmt"

func main() {
	defer func() {
		if r := recover(); r != nil {
			fmt.Printf("%v,%T\n", r, r)
		}
	}()
	
	panic("a problem")
}
// Output:
// a problem,string
最后修改 October 10, 2024: 更新 (a4b8f85)