You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

panic.go 550B

12345678910111213141516171819
  1. // Copyright (c) 2021 Shivaram Lingamneni
  2. // released under the MIT license
  3. package irc
  4. import (
  5. "fmt"
  6. "runtime/debug"
  7. )
  8. // HandlePanic is a general-purpose panic handler for ad-hoc goroutines.
  9. // Because of the semantics of `recover`, it must be called directly
  10. // from the routine on whose call stack the panic would occur, with `defer`,
  11. // e.g. `defer server.HandlePanic()`
  12. func (server *Server) HandlePanic() {
  13. if r := recover(); r != nil {
  14. server.logger.Error("internal", fmt.Sprintf("Panic encountered: %v\n%s", r, debug.Stack()))
  15. }
  16. }