Skip to content

Instantly share code, notes, and snippets.

@AnuchitO
Last active September 26, 2019 00:48
Show Gist options
  • Save AnuchitO/e755c956fddca7d21ca8c326be85e8c6 to your computer and use it in GitHub Desktop.
Save AnuchitO/e755c956fddca7d21ca8c326be85e8c6 to your computer and use it in GitHub Desktop.
errOriginal := &os.PathError{Op: "read", Path: "/a/b", Err: errors.New("read error")}
// ไม่ได้ห่อ แค่สร้าง error ใหม่จาก error เดิม
err := fmt.Errorf("create new error: %v", errOriginal)
fmt.Printf("error value: %T\n", err)
// สร้าง error ใหม่ ยังเก็บ(ห่อ) type เดิมไว้ข้างใน
err = fmt.Errorf("wrapped error: %w", errOriginal)
fmt.Printf("error value: %T\n", err)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment