mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-23 13:52:26 +08:00
test&doc: add example and update doc for xerror package
This commit is contained in:
25
xerror/xerror_example_test.go
Normal file
25
xerror/xerror_example_test.go
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package xerror
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"reflect"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ExampleUnwrap() {
|
||||||
|
result1 := Unwrap(strconv.Atoi("42"))
|
||||||
|
fmt.Println(result1)
|
||||||
|
|
||||||
|
_, err := strconv.Atoi("4o2")
|
||||||
|
defer func() {
|
||||||
|
v := recover()
|
||||||
|
result2 := reflect.DeepEqual(err.Error(), v.(*strconv.NumError).Error())
|
||||||
|
fmt.Println(result2)
|
||||||
|
}()
|
||||||
|
|
||||||
|
Unwrap(strconv.Atoi("4o2"))
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// 42
|
||||||
|
// true
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user