From a930511054925215931dc5b5f24a032c78168320 Mon Sep 17 00:00:00 2001 From: dudaodong Date: Sun, 8 Jan 2023 20:36:32 +0800 Subject: [PATCH] test&doc: add example and update doc for xerror package --- xerror/xerror_example_test.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 xerror/xerror_example_test.go diff --git a/xerror/xerror_example_test.go b/xerror/xerror_example_test.go new file mode 100644 index 0000000..512655f --- /dev/null +++ b/xerror/xerror_example_test.go @@ -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 +}