Skip to content

Instantly share code, notes, and snippets.

@pkbhowmick
Created December 21, 2021 06:54
Show Gist options
  • Save pkbhowmick/94a9a8becefe8b3679fe4a51ecbc90ec to your computer and use it in GitHub Desktop.
Save pkbhowmick/94a9a8becefe8b3679fe4a51ecbc90ec to your computer and use it in GitHub Desktop.
package main
import "fmt"
var res int
func main() {
res = -1
ch := make(chan bool)
go divide(ch, 10, 0)
val := <-ch
if val {
fmt.Println(res)
} else {
fmt.Println("something wrong")
}
}
func divide(ch chan bool, a, b int) {
defer func() {
if err := recover(); err != nil {
fmt.Println("panic occured")
ch <- false
}
ch <- true
}()
res = (a / b)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment