go error实用处理

import (
	"log"
	"runtime"
)

func main() {
	test()
}

func test() {
	test2()
}

func test2(){
	pc,file,line,ok := runtime.Caller(0)
	log.Println(pc)
	log.Println(file)
	log.Println(line)
	log.Println(ok)
	f := runtime.FuncForPC(pc)
	log.Println(f.Name())

	pc,file,line,ok = runtime.Caller(1)
	log.Println(pc)
	log.Println(file)
	log.Println(line)
	log.Println(ok)
	f = runtime.FuncForPC(pc)
	log.Println(f.Name())
	pc,file,line,ok = runtime.Caller(2)
	log.Println(pc)
	log.Println(file)
	log.Println(line)
	log.Println(ok)
	f = runtime.FuncForPC(pc)
	log.Println(f.Name())
}
//output:
2019/06/27 09:28:30 4827604
2019/06/27 09:28:30 E:****/errjun.go
2019/06/27 09:28:30 17
2019/06/27 09:28:30 true
2019/06/27 09:28:30 main.test2
2019/06/27 09:28:30 4827527
2019/06/27 09:28:30 E:****/errjun.go
2019/06/27 09:28:30 13
2019/06/27 09:28:30 true
2019/06/27 09:28:30 main.test
2019/06/27 09:28:30 4827522
2019/06/27 09:28:30 E:****/errjun.go
2019/06/27 09:28:30 9
2019/06/27 09:28:30 true
2019/06/27 09:28:30 main.main

 

你可能感兴趣的:(go)