Add recover

This commit is contained in:
Sangeeth Sudheer 2024-05-01 18:58:54 +05:30
parent f1fe463b05
commit 693eca244b
Signed by: x
GPG Key ID: F6D06ECE734C57D1
2 changed files with 23 additions and 2 deletions

View File

@ -20,7 +20,8 @@ package main
// import "git.sangeeth.dev/gobyexample/statefulgoroutines" // import "git.sangeeth.dev/gobyexample/statefulgoroutines"
// import "git.sangeeth.dev/gobyexample/sorting" // import "git.sangeeth.dev/gobyexample/sorting"
// import "git.sangeeth.dev/gobyexample/panic" // import "git.sangeeth.dev/gobyexample/panic"
import "git.sangeeth.dev/gobyexample/defers" // import "git.sangeeth.dev/gobyexample/defers"
import "git.sangeeth.dev/gobyexample/recovering"
func main() { func main() {
// runes.Runes() // runes.Runes()
@ -43,5 +44,6 @@ func main() {
// statefulgoroutines.StatefulGoroutines() // statefulgoroutines.StatefulGoroutines()
// sorting.Sorting() // sorting.Sorting()
// panic.Panic() // panic.Panic()
defers.Defers() // defers.Defers()
recovering.Recover()
} }

19
recovering/recovering.go Normal file
View File

@ -0,0 +1,19 @@
package recovering
import "fmt"
func Recover() {
defer func() {
if r := recover(); r != nil {
fmt.Printf("Whew. Recovered from panic %v\n", r)
}
}()
doPanic()
fmt.Printf("I'll never execute >...<")
}
func doPanic() {
panic("aaaaaaaaaaahhhhhhhhhh sjdnsjdnsdjnsd")
}