# README
exception
panic
recover()
usually returns (interface{} or any), and always need to parse to error
type
package main
import (
"fmt"
"github.com/lowl11/boost/pkg/io/exception"
)
func main() {
defer func() {
if err := exception.CatchPanic(recover()); err != nil {
fmt.Println("catch panic err:", err)
}
}()
}
Try
package main
import (
"fmt"
"github.com/lowl11/boost/pkg/io/exception"
)
func main() {
if err := exception.Try(do); err != nil {
fmt.Println(err)
// print "PANIC RECOVER: runtime error: index out of range [3] with length 0"
}
}
func do() error {
arr := make([]int, 0)
fmt.Println(arr[3]) // index out of range panic
return nil
}