package main
import "fmt"
func test(i int){
defer func(){
if r := recover(); r != nil {
fmt.Println("Inside Recover: ", r)
}
}()
for try := 1 ; try <= i ; try++{
if (i == 3){
panic("Panic")
}
fmt.Printf("i: %d try: %d
", i , try)
}
}
func main(){
for i := 1 ; i < 5 ; i++{
test(i)
}
}
The method panics and skips to next i
value without trying i
times. Is there a way in which we can recover from the panic and retry for the same value of i
that caused panic ?