草庐IT

Deferred

全部标签

Go:从 defer 中返回

如果函数发生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-

Go:从 defer 中返回

如果函数发生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-