Skip to content

Commit 6389c28

Browse files
authored
Update README.md
1 parent d60aec2 commit 6389c28

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,37 @@ work_2 ...
3434
work_1 ...
3535
:shutdown
3636
```
37+
38+
<br>
39+
40+
## X errcause
41+
42+
```go
43+
package main
44+
45+
import (
46+
"github.com/matsuwin/siggroup/x/errcause"
47+
"github.com/pkg/errors"
48+
"io/ioutil"
49+
)
50+
51+
func mkError() error {
52+
_, err := ioutil.ReadFile("xxx.txt")
53+
return errors.New(err.Error())
54+
}
55+
56+
func main() {
57+
58+
// 错误恢复 recover call errcause.Keep
59+
defer func() {
60+
if ei := recover(); ei != nil {
61+
errcause.Keep(ei)
62+
}
63+
}()
64+
65+
// 模拟一个错误抛出调用
66+
if err := mkError(); err != nil {
67+
panic(err)
68+
}
69+
}
70+
```

0 commit comments

Comments
 (0)