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
Exercício: Capítulo 24, Exercício 4 (Nível: 11)
Use esta thread para compartilhar sua solução, discutir o exercício com os colegas e pedir ajuda caso tenha dificuldades!
The text was updated successfully, but these errors were encountered:
https://play.golang.org/p/21DbEstR0_q
package main /* - Utilizando este código: https://play.golang.org/p/wlEM1tgfQD - ...use o struct sqrt.Error como valor do tipo erro. */ import ( "fmt" "log" ) type sqrtError struct { lat string long string err error } func (se sqrtError) Error() string { return fmt.Sprintf("math error: lat: %v | long: %v | valor: %v", se.lat, se.long, se.err) } func main() { test, err := sqrt(-10.23) if err != nil { log.Println(err) } fmt.Println(test) } func sqrt(f float64) (float64, error) { fmt.Println("esse eh o valor de f:", float64(f)) if f < 0 { return 0, sqrtError{lat: "1337", long: "1338", err: fmt.Errorf("%v", f)} } return 42, nil }
Output
eduardo@ubuntu:~/newCodes/04$ go run main.go esse eh o valor de f: -10.23 2021/03/24 14:44:53 math error: lat: 1337 | long: 1338 | valor: -10.23 0
Sorry, something went wrong.
package main import ( "errors" "fmt" "log" ) type sqrtError struct { lat string long string err error } func (se sqrtError) Error() string { return fmt.Sprintf("math error: %v - %v - %v", se.lat, se.long, se.err) } func main() { _, err := sqrt(-10.23) if err != nil { log.Println(err) } } func sqrt(f float64) (float64, error) { if f < 0 { return f, sqrtError{ lat: "10", long: "21", err: errors.New("Valor passado menor que 0"), } } return 42, nil }
No branches or pull requests
Exercício: Capítulo 24, Exercício 4 (Nível: 11)
Use esta thread para compartilhar sua solução, discutir o exercício com os colegas e pedir ajuda caso tenha dificuldades!
The text was updated successfully, but these errors were encountered: