Recovering panics into errors
Experimenting with system memory panics
Import package:
import "github.com/PuppyKhan/catchpanic"
Add catchall with defer
:
func foo() (err error) {
defer catchpanic.ToError(&err)
// panic prone code
}
There are actually 3 distinct types of panics in Go
- Recoverable user thrown panics
- Recoverable minor system panics
- Unrecoverable system panics
The benevolent overlords of Go deemed it impossible to catch all system panics, especially when it comes to running out of memory.
Fundamentally, the role of a garbage collector is to present to the programmer the illusion of an infinite free store.
If that illusion is broken, is seems reasonable to abort the program. -davecheney #facepalm
Luigi Kapaj