We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error defining/handling examples mostly outdated since go 1.13 as there was %w directive introduced for fmt.Errorf() function.
%w
fmt.Errorf()
Something like this can be used if you want to introduce details into the error itself. No need to define yet another struct+interface for that:
import ( "errors" "fmt" ) var ErrSomeStaticError = errors.New("static error") func main() { err := ReturnErrorWithDetails() if errors.Is(err, ErrSomeStaticError){ fmt.Printf("found static error with details: %v\n", err) fmt.Printf("just static error: %v\n", errors.Unwrap(err)) } else { fmt.Print("static error not found") } } func ReturnErrorWithDetails() error { return fmt.Errorf("some details here, item count: %d, vector name: %s: %w", 10, "infinity", ErrSomeStaticError) }
The text was updated successfully, but these errors were encountered:
Hi @zolia, I agree that the article should be changed to including the above instead 🙇
Sorry, something went wrong.
No branches or pull requests
Error defining/handling examples mostly outdated since go 1.13 as there was
%w
directive introduced forfmt.Errorf()
function.Something like this can be used if you want to introduce details into the error itself. No need to define yet another struct+interface for that:
The text was updated successfully, but these errors were encountered: