panic()recover()
panic()
看代码:
结果:
ubuntu@VM-0-15-ubuntu:~/taoge/go$ go run test.go
a
c
d
panic: 10000
goroutine 1 [running]:
panic(0x4b8480, 0xc82000a2c0)
/usr/lib/go-1.6/src/runtime/panic.go:481 +0x3e6
main.f()
/home/ubuntu/taoge/go/test.go:34 +0x115
main.main()
/home/ubuntu/taoge/go/test.go:25 +0x35
exit status 2
ubuntu@VM-0-15-ubuntu:~/taoge/go$
看代码:
结果:
ubuntu@VM-0-15-ubuntu:~/taoge/go$ go run test.go
a
c
10000
haha
d
ubuntu@VM-0-15-ubuntu:~/taoge/go$
好好体会下。
总结
原文链接:https://blog.csdn.net/stpeace/article/details/82902640