gotry/README.md
2022-03-27 03:03:42 +02:00

30 lines
512 B
Markdown

# gotry
This package is a fork of lainio's [err2](https://github.com/lainio/err2)
package.
## Handle errors
Instead of the idiomatic go way of handling errors, which involves if-conditions for every possible
error, ...
```go
func myFunction() (err error) {
b, err := ioutil.ReadAll(r)
if err != nil {
return err
}
}
```
you can wrap the error-throwing function in a try wrapper.
```go
func myFunction() (err error) {
defer err2.Return(&err)
b := try.Bytes(ioutil.ReadAll(r))
return
}
```