1
0
mirror of https://github.com/charlienet/go-mixed.git synced 2025-07-17 16:12:42 +08:00
Files
go-mixed/panic/panic_test.go
2022-07-04 12:01:44 +08:00

33 lines
464 B
Go

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("这条消息可打印")
}