Documentation
¶
Overview ¶
Package panic_recovery provides utilities for recovering from panics in Go applications. It captures the panic value, formats it with a stack trace, and passes the result to a provided callback function for handling.
The primary function, Recover, is intended to be used in a defer statement to catch panics that occur in the calling goroutine.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Recover ¶
func Recover(formatRes func(err error))
Recover captures a panic, formats it with a stack trace, and passes the resulting error to the provided callback function. It should typically be called via defer to handle panics in the current goroutine.
The formatRes function is invoked with a wrapped error containing the panic value and the current goroutine's stack trace. If no panic has occurred, Recover returns immediately without calling formatRes.
Example usage:
defer Recover(func(err error) {
log.Printf("Recovered from panic: %v", err)
})
Types ¶
This section is empty.