Choose a recover method

Report a typo

You have a code with a defined recover function, named panicHandler(). Try to produce a direct panic message to get the message "Second signal handled!" from the panicHandler() function.

Write a program in Go
package main

import "fmt"

func panicHandler() {
signal := recover()

switch signal {
case "first":
fmt.Println("First signal catched!")
case "second":
fmt.Println("Second signal handled!")
default:
fmt.Println("Undefined signal")
}
}

func main() {
defer panicHandler()

panic(?)
}
___

Create a free account to access the full topic