cloudaice / learnGo

there are something about Go Useage
MIT License
0 stars 0 forks source link

使用Panic的几种情形 #17

Open cloudaice opened 8 years ago

cloudaice commented 8 years ago
  1. 对崩溃的程序进行检查,判断是何种崩溃
if r := recover(); r != nil {
    if r == xxxx
}
  1. 当前进程继续运行已经无意义
db, err := InitDB("xxx")
if err != nil {
    panic(err)
}
  1. 执行了错误的语义
a.Acquire()
a.Release()
a.Release() // should panic