func main() {
defer fmt.Println("Main defer")
go t1()
go t2()
go t3()
time.Sleep(20 * time.Second)
}
func t1() {
defer fmt.Println("t1 defer")
time.Sleep(20 * time.Second)
}
func t2() {
defer fmt.Println("t2 defer")
time.Sleep(5 * time.Second)
panic(New("T2"))
}
func t3() {
defer fmt.Println("t3 defer")
time.Sleep(20 * time.Second)
}
1 thread (t2) calls panic, t2 defer gets called. when t2 panics, every other thread is also terminated. I want every thread's defer to be called. It's a scenario where panic is must, panic is in one thread.. So I want every thread to be aware that program is going to exit. Any approach I can achieve that?
present output:
t2 defer
panic: T2
goroutine 19 [running]:
main.t2()
C:/Users/Talha.Irfan/OneDrive - Bentley Systems, Inc/Desktop/go_test/src/main2/main.go:34 +0x105
created by main.main
C:/Users/Talha.Irfan/OneDrive - Bentley Systems, Inc/Desktop/go_test/src/main2/main.go:21 +0xb0