mirror of
https://github.com/charlienet/go-mixed.git
synced 2025-07-18 00:22:41 +08:00
33 lines
464 B
Go
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("这条消息可打印")
|
|
}
|