Can I recover and retry a panic?

How do I recover and continue from a panic (E.g. resume where I left off? Could do something like this (pseudocode):

func main() { 
   defer errorfix()
   ....'overflow' panic
   ....'divide by zero' panic

func errorfix() {
   if err := recover(); err !=nil { 
     ... fix something based on err and then 
     return to retry
     // or return to next line
     // or panic('unknown error')

I think not. Once current program run into a panic, it would reclaim the stack your function (in your code, the main() ) had claimed, so you would not get the chance.

Consider embedding the code in an anonymous function so that panic-ing, then defer recovery only exits that function.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.