functryRecover(){deferfunc(){
r :=recover()if r ==nil{
fmt.Println("Nothing to recover. "+"Please try uncomment errors "+"below.")return}if err, ok := r.(error); ok {
fmt.Println("Error occurred:", err)}else{panic(fmt.Sprintf("I don't know what to do: %v", r))}}()// Uncomment each block to see different panic// scenarios.// Normal errorpanic(errors.New("this is an error"))// Output : Error occurred: this is an error// Division by zero
b :=0
a :=5/ b
fmt.Println(a)// Output : Error occurred: runtime error: // integer divide by zero// Causes re-panicpanic(123)// Output :// panic: 123 [recovered]// panic: I don't know what to do: 123}funcmain(){tryRecover()}