Documentation ¶
Overview ¶
Package pan (short for panic) can be used to implement internal error propagation via panic and recover. A benefit over naive panic/recover usage is that runtime errors and other unrelated panics are disregarded.
The check, must and mustcheck subpackages are designed to be used via dot imports (if that's something you prefer).
Example 1
import "import.name/pan" func check(err error) { pan.Check(err) } func must[T any](x T, err error) T { return pan.Must(x, err) } func internal() string { check(os.Chdir("/nonexistent")) return must(os.Getwd()) } func Public() (s string, err error) { err = pan.Recover(func() { s = internal() }) return }
Example 2
import ( "import.name/pan" . "import.name/pan/mustcheck" ) func internal() string { Check(os.Chdir("/nonexistent")) return Must(os.Getwd()) } func Public() (s string, err error) { err = pan.Recover(func() { s = internal() }) return }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Error ¶
func Error(x interface{}) error
Error returns an error if x is a value created by Check, Must, Panic or Wrap. If x is nil, nil is returned. If x is something else, Error panics with x as the panic value.
func Fatal ¶
func Fatal(x interface{})
Fatal is like Error, but the error is written to stderr and the program terminates with exit status 1.
func Must ¶ added in v0.2.0
Must panics if err is not nil. Otherwise it returns x. See Error, Fatal and Recover.
func Panic ¶ added in v0.2.0
func Panic(err error)
Panic unconditionally. See Error, Fatal and Recover.
Types ¶
This section is empty.
Directories ¶
Path | Synopsis |
---|---|
Package check will export only symbols prefixed with word Check.
|
Package check will export only symbols prefixed with word Check. |
Package must will export only symbols prefixed with word Must.
|
Package must will export only symbols prefixed with word Must. |
Package mustcheck will export only symbols prefixed with words Check or Must.
|
Package mustcheck will export only symbols prefixed with words Check or Must. |