-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
chaoyuepan
committed
Apr 29, 2024
1 parent
ef695a9
commit 082ab0c
Showing
4 changed files
with
6 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
# Tip #8 包裹错误 | ||
# Tip #8 错误封装 | ||
|
||
> 原始链接:[Golang Tip #8: Wrapping Errors](https://twitter.com/func25/status/1729768084100300945) | ||
> | ||
通常,我们会使用`fmt.Errorf`和`%w`把一个错误包裹到另外一个错误里,像这样: | ||
通常,我们会使用`fmt.Errorf`和`%w`把一个错误封装到另外一个错误里,像这样: | ||
|
||
![](./images/008/008_01.png) | ||
|
||
但是在Go 1.20,我们有一个更直接和友好的方法去包裹错误,那就是使用`errors.Join()`: | ||
但是在Go 1.20,我们有一个更直接和友好的方法去错误封装,那就是使用`errors.Join()`: | ||
|
||
![](./images/008/008_02.jpg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters