How to override Beego's recoverPanic? I have set the flag recoverpanic = false
and write my own recover but have no luck, it just print the panic message to the console instead jumping to my recover function.
func main() {
defer recoverPanic()
beego.Run()
}
func recoverPanic() {
if err := recover(); err != nil {
fmt.Println("Panic should go there")
}
}
I want to catch all unexpect errors, e.g nil pointer
, write some log and send email to our maintainers.
You should add recoverPanic
at the beginning of every goroutine. You add the recover
in the main
function and it won't cache the panic
of request.
Try this in Beego:
func (c *MainController) Get() {
defer recoverPanic()
... Your Code ...
}