MCPcopy Create free account
hub / github.com/baidu/EasyFaaS / HandleCrash

Function HandleCrash

pkg/util/runtime/runtime.go:48–61  ·  view source on GitHub ↗

HandleCrash simply catches a crash and logs an error. Meant to be called via defer. Additional context-specific handlers can be provided, and will be called in case of panic. HandleCrash actually crashes, after calling the handlers and logging the panic message. TODO: remove this function. We are

(additionalHandlers ...func(interface{}))

Source from the content-addressed store, hash-verified

46// catching panics was important. But it's actually much simpler for montoring
47// software if we just exit when an unexpected panic happens.
48func HandleCrash(additionalHandlers ...func(interface{})) {
49 if r := recover(); r != nil {
50 for _, fn := range PanicHandlers {
51 fn(r)
52 }
53 for _, fn := range additionalHandlers {
54 fn(r)
55 }
56 if ReallyCrash {
57 // Actually proceed to panic.
58 panic(r)
59 }
60 }
61}
62
63// logPanic logs the caller tree when a panic occurs.
64func logPanic(r interface{}) {

Callers 2

TestHandleCrashFunction · 0.85
TestCustomHandleCrashFunction · 0.85

Calls

no outgoing calls

Tested by 2

TestHandleCrashFunction · 0.68
TestCustomHandleCrashFunction · 0.68