pan

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2021 License: BSD-3-Clause Imports: 2 Imported by: 17

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.

Example

import "import.name/pan"

func check(err error)                 { pan.Check(err) }
func checked[T any](x T, err error) T { pan.Check(err); return x }

func internal() string {
    check(os.Chdir("/nonexistent"))
    return checked(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 Check

func Check(err error)

Check panics unless err is nil.

func Error

func Error(x interface{}) error

Error returns an error if x is a panic value from Check. 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 Recover

func Recover(f func()) (err error)

Recover invokes f and returns any error value passed to Check.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL