Add recover
This commit is contained in:
parent
f1fe463b05
commit
693eca244b
6
main.go
6
main.go
@ -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
19
recovering/recovering.go
Normal 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")
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user