diff options
Diffstat (limited to 'debug/debug.go')
-rw-r--r-- | debug/debug.go | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/debug/debug.go b/debug/debug.go index c6f367e..3e32125 100644 --- a/debug/debug.go +++ b/debug/debug.go @@ -29,6 +29,8 @@ import ( ) var writer io.Writer +var RecoverPrettyPanic bool +var OnRecover func() func init() { var err error @@ -59,6 +61,22 @@ func PrintStack() { } } +// Recover recovers a panic, runs the OnRecover handler and either re-panics or +// shows an user-friendly message about the panic depending on whether or not +// the pretty panic mode is enabled. +func Recover() { + if p := recover(); p != nil { + if OnRecover != nil { + OnRecover() + } + if RecoverPrettyPanic { + PrettyPanic(p) + } else { + panic(p) + } + } +} + const Oops = ` __________ < Oh noes! > ‾‾‾\‾‾‾‾‾‾ |