SHARE
TWEET

Untitled

a guest Jul 21st, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package main
  2.  
  3. import (
  4.         "errors"
  5.         "fmt"
  6. )
  7.  
  8. func main() {
  9.         errs := []error{
  10.                 errors.New("errors.New error"),
  11.                 fmt.Errorf("fmt.Errorf error (no wrapping)"),
  12.                 fmt.Errorf(
  13.                         "fmt.Errorf wrapping errors.New error: %w",
  14.                         errors.New("base errors.New error")),
  15.                 fmt.Errorf(
  16.                         "fmt.Errorf wrapping fmt.Errorf error: %w",
  17.                         fmt.Errorf("base fmt.Errorf error")),
  18.                 fmt.Errorf(
  19.                         "fmt.Errorf wrapping fmt.Errorf wrapping errors.New: %w",
  20.                         fmt.Errorf("middle error: %w", errors.New("base error"))),
  21.         }
  22.         for _, err := range errs {
  23.                 fmt.Printf("before:    %v\nunwrapped: %v\n\n", err, errors.Unwrap(err))
  24.         }
  25. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top