Closed
Description
What did you do?
In Go,Unable to receive the panic of the sub-goroutine in the parent-goroutine.
func main() {
defer func() {
if r := recover(); r != nil {
fmt.Println("recover()")
}
return
}()
g, _ := errgroup.WithContext(context.Background())
g.Go(func() error {
panic("this is a panic")
})
if err := g.Wait(); err != nil {
fmt.Println("occur err")
return
}
time.Sleep(500 * time.Millisecond)
fmt.Println("success")
return
}
output:
panic: this is a panic
goroutine 6 [running]:
...
...
What did you expect to see?
What I hope is that there can be a structure similar to errgroup
, like panicgroup
to deal with the appearance of panic in the sub-goroutine.
PS
I can implement this function if needed