diff --git a/docs/xerror.md b/docs/xerror.md index c760bb9..1a1dc54 100644 --- a/docs/xerror.md +++ b/docs/xerror.md @@ -22,20 +22,20 @@ import ( ## Index -- [Unwrap](#Unwrap) +- [TryUnwrap](#TryUnwrap)
## Documentation -### Unwrap +### TryUnwrap -

Unwrap if err is nil then it returns a valid value. If err is not nil, Unwrap panics with err.

+

TryUnwrap if err is nil then it returns a valid value. If err is not nil, Unwrap panics with err.

Signature: ```go -func Unwrap[T any](val T, err error) T +func TryUnwrap[T any](val T, err error) T ``` Example: @@ -49,7 +49,7 @@ import ( ) func main() { - result1 := xerror.Unwrap(strconv.Atoi("42")) + result1 := xerror.TryUnwrap(strconv.Atoi("42")) fmt.Println(result1) _, err := strconv.Atoi("4o2") @@ -59,7 +59,7 @@ func main() { fmt.Println(result2) }() - xerror.Unwrap(strconv.Atoi("4o2")) + xerror.TryUnwrap(strconv.Atoi("4o2")) // Output: // 42 diff --git a/docs/xerror_zh-CN.md b/docs/xerror_zh-CN.md index 0a466df..8ebc0da 100644 --- a/docs/xerror_zh-CN.md +++ b/docs/xerror_zh-CN.md @@ -22,20 +22,20 @@ import ( ## 目录 -- [Unwrap](#Unwrap) +- [TryUnwrap](#TryUnwrap)
## 文档 -### Unwrap +### TryUnwrap -

检查error, 如果err为nil则展开,则它返回一个有效值,如果err不是nil则Unwrap使用err发生panic。

+

检查error, 如果err为nil则展开,则它返回一个有效值,如果err不是nil则TryUnwrap使用err发生panic。

函数签名: ```go -func Unwrap[T any](val T, err error) T +func TryUnwrap[T any](val T, err error) T ``` 示例: @@ -49,7 +49,7 @@ import ( ) func main() { - result1 := xerror.Unwrap(strconv.Atoi("42")) + result1 := xerror.TryUnwrap(strconv.Atoi("42")) fmt.Println(result1) _, err := strconv.Atoi("4o2") @@ -59,7 +59,7 @@ func main() { fmt.Println(result2) }() - xerror.Unwrap(strconv.Atoi("4o2")) + xerror.TryUnwrap(strconv.Atoi("4o2")) // Output: // 42