Skip to content
This repository has been archived by the owner on Aug 27, 2021. It is now read-only.

Latest commit

 

History

History
42 lines (31 loc) · 1.06 KB

README.md

File metadata and controls

42 lines (31 loc) · 1.06 KB

Please use https://github.com/mitchellh/panicwrap as it does not use some nasty memory patching.

go-panichandler GoDoc go-report

Handle panics globaly.

Golang lets you not handle panics in subroutines in an easy way.

This package uses dirty memory patching techniques to supply this feature.

Use with care!

Usecases

  • Send a panic to an error tracking service
  • Gracefully close the application
  • ...

Example

package main

import (
	"os"
	"encoding/json"
	"github.com/talon-one/go-panichandler"
)

func main() {
	panichandler.OnPanic(func(v interface{}) interface{} {
		fmt.Printf("Catched a panic: %v\n", v)
		return v
	})

	ch := make(chan struct{})
	go func() {
		panic("Hello World")
		ch <- struct{}{}
	}()
	<-ch
}