Documentation ¶
Overview ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Recover ¶
Recover returns an error that represents an error caught from recover. When passed nil, returns nil.
It should be used as:
if err := Recover(recover()); err != nil { // ... handle here ... }
func Safe ¶
Safe calls and returns the value of f. If a panic occurs, t is set to the zero value, and error as returned by Recover.
Example ¶
package main import ( "errors" "fmt" "github.com/tkw1536/pkglib/recovery" ) func main() { // a function that doesn't return an error is invoked normally fmt.Println( recovery.Safe(func() (int, error) { return 42, nil }), ) fmt.Println( recovery.Safe(func() (int, error) { return 0, errors.New("some error") }), ) { res, err := recovery.Safe(func() (int, error) { panic("test panic") }) fmt.Printf("%d %#v\n", res, err) } }
Output: 42 <nil> 0 some error 0 recovery.recovered{/* recover() = "test panic" */}
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.