|
You are here |
grosser.it | ||
| | | | |
www.4async.com
|
|
| | | | | ???????golang/x/exp???????????xerrors???????????golang/x/exp???????errors??????????????????\nPackage errors implements functions to manipulate errors. This package implements the Go 2 draft designs for error inspection and printing ?????????????????????????????????????????github.com/pkg/errors?????????????\n????error? ???????????github.com/pkg/errors??????????Go????????????????????????????\npackage main import ( "fmt" "golang.org/x/exp/xerrors" ) func raiseError() error { return xerrors.New("a new error") } func main() { err := xerrors.Errorf("raiseError: %w", raiseError()) fmt.Println(err) } ?????\nraiseError: a new error ??????????github.com/pkg/errors?????????xerrors.Errorf??????errors.Wrap???? ????????%w??????????????????????????\n???????????????????????... | |
| | | | |
miparnisariblog.wordpress.com
|
|
| | | | | From simpler to more complex: 1. errors.New() or fmt.Errorf() without a sentinel error Only use for quick prototyping 2. Sentinel errors When you have an interface and want implementations to be able to throw errors and then catch them to run some logic But! you won't be able to customize the error thrown var (... | |
| | | | |
cep.dev
|
|
| | | | | An experience using Go where the type system was a problem | |
| | | | |
cosmiaineurope.wordpress.com
|
|
| | | Cosmia's travel in Europe from June 2018 to July 2018 | ||