package main
func main() {
test()
print("world after panic")
}
func test() {
defer func() {
if err := recover(); err != nil {
print("catched panic, ha ha ha...")
}
}()
panic("noooo")
}
package main
- default package declarationfunc main() {
- declaremain
function that will be launched automaticallyfunc test()
- test function haspanic()
call and its handler viarecover()
if err := recover()
- catch panic viarecover()
print("world after panic")
- this should would if panic was catches successfully
group: panic
package main
func main() {
test()
print("world after panic")
}
func test() {
defer func() {
if err := recover(); err != nil {
print("catched panic, ha ha ha...")
}
}()
panic("noooo")
}
catched panic, ha ha ha...world after panic