Created
December 21, 2021 06:54
-
-
Save pkbhowmick/94a9a8becefe8b3679fe4a51ecbc90ec to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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