标签:java ef c as print 函数 class r Go
panic 抛出异常
recover 捕获异常 捕获后会返回外层函数继续执行
defer 函数退出之前执行
func panicOut() {
print(5) panic("error") print(6)
}
func recoverHere() {
print(3) defer func(){ err := recover() print(err) }() panicOut() print(4)
}
func outFunc(){
print(1) recoverHere() print(2)
}
func main(){
outFunc()
}
输出:
1
3
5
error
2
标签:java ef c as print 函数 class r Go
原文地址:http://my.oschina.net/beloser/blog/307607