recover.go 308 B

12345678910111213141516
  1. package rescue
  2. import "github.com/tal-tech/go-zero/core/logx"
  3. // Recover is used with defer to do cleanup on panics.
  4. // Use it like:
  5. // defer Recover(func() {})
  6. func Recover(cleanups ...func()) {
  7. for _, cleanup := range cleanups {
  8. cleanup()
  9. }
  10. if p := recover(); p != nil {
  11. logx.ErrorStack(p)
  12. }
  13. }