mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 00:43:26 +08:00
13.0-13.10
This commit is contained in:
@@ -14,7 +14,6 @@ func main() {
|
||||
panic("A severe error occurred: stopping the program!")
|
||||
fmt.Println("Ending the program")
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
输出如下:
|
||||
@@ -33,7 +32,6 @@ runtime.goexit /go/src/pkg/runtime/proc.c:148
|
||||
runtime.goexit()
|
||||
---- Error run E:/Go/GoBoek/code examples/chapter 13/panic.exe with code Crashed
|
||||
---- Program exited with code -1073741783
|
||||
|
||||
```
|
||||
|
||||
一个检查程序是否被已知用户启动的具体例子:
|
||||
@@ -46,7 +44,6 @@ func check() {
|
||||
panic(“Unknown user: no value for $USER”)
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
可以在导入包的 init() 函数中检查这些。
|
||||
@@ -57,8 +54,7 @@ func check() {
|
||||
if err != nil {
|
||||
panic(“ERROR occurred:” + err.Error())
|
||||
}
|
||||
|
||||
```
|
||||
```
|
||||
|
||||
<u>Go panicking</u>:
|
||||
|
||||
@@ -68,7 +64,6 @@ if err != nil {
|
||||
|
||||
不能随意地用 panic 中止程序,必须尽力补救错误让程序能继续执行。
|
||||
|
||||
|
||||
## 链接
|
||||
|
||||
- [目录](directory.md)
|
||||
|
Reference in New Issue
Block a user