如果函数发生panic(在Go中),我想从函数返回错误:funcgetReport(filenamestring)(repreport,errerror){rep.data=make(map[string]float64)deferfunc(){ifr:=recover();r!=nil{fmt.Println("Recoveredinf",r)err,_=r.(error)returnnil,err}}()panic("Reportformatnotrecognized.")//restofthegetReportfunction,whichcantrytoout-of-bound-
如果函数发生panic(在Go中),我想从函数返回错误:funcgetReport(filenamestring)(repreport,errerror){rep.data=make(map[string]float64)deferfunc(){ifr:=recover();r!=nil{fmt.Println("Recoveredinf",r)err,_=r.(error)returnnil,err}}()panic("Reportformatnotrecognized.")//restofthegetReportfunction,whichcantrytoout-of-bound-