Documentation
¶
Overview ¶
Package panichandle handles panic.
Example ¶
ctx := context.Background() ctx = SetHandlerToContext(ctx, func(ctx context.Context, r any) { fmt.Println("Panic:", r) }) defer Recover(ctx) panic("test")
Output: Panic: test
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Recover ¶
Recover recovers panic and calls the Handler returned by GetHandler.
If there is no Handler, it doesn't recover.
It should be called in defer.
func SetHandlerToContext ¶ added in v0.4.1
SetHandlerToContext sets a Handler to a context.Context.
Types ¶
type ErrorHandler ¶ added in v0.3.0
ErrorHandler is a Handler that converts the recovered value to error with Convert, and calls Handler.
If the recovered value is already an error, Convert is not called.
type Handler ¶
Handler is a function that handles panic.
func GetHandler ¶ added in v0.4.1
GetHandler gets a Handler from a context.Context or the DefaultHandler.
It may return nil.
func GetHandlerFromContext ¶ added in v0.4.1
GetHandlerFromContext gets a Handler from a context.Context.
It returns nil if no Handler is set.
Click to show internal directories.
Click to hide internal directories.