mirror of
https://github.com/charlienet/go-mixed.git
synced 2025-07-18 00:22:41 +08:00
优化range引用
This commit is contained in:
32
panic/panic_test.go
Normal file
32
panic/panic_test.go
Normal file
@ -0,0 +1,32 @@
|
||||
package panic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestPanic(t *testing.T) {
|
||||
defer func() {
|
||||
t.Log("捕捉异常")
|
||||
if e := recover(); e != nil {
|
||||
if err, ok := e.(error); ok {
|
||||
t.Log(err.Error())
|
||||
}
|
||||
t.Log("格式化:", e)
|
||||
}
|
||||
}()
|
||||
|
||||
g := NewPanicGroup(10)
|
||||
g.Go(func() {
|
||||
panic("1243")
|
||||
})
|
||||
|
||||
if err := g.Wait(context.Background()); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
time.Sleep(1 * time.Second)
|
||||
fmt.Println("这条消息可打印")
|
||||
}
|
Reference in New Issue
Block a user