panic golang code example
Example: golang panic
// example panic, defer and recover
package main
import "fmt"
func recoveryPanic() {
if recoveryMessage := recover(); recoveryMessage != nil {
fmt.Println(recoveryMessage)
}
}
func main() {
name := "jane doe"
if name != "john doe" {
defer recoveryPanic()
panic("name is not john doe")
} else {
fmt.Println("nama saya adalah", name)
}
}