Skip to content
New issue

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 3 (Nível: 11) #75

Open
vkorbes opened this issue Sep 30, 2020 · 2 comments
Open

Exercício: Capítulo 24, Exercício 3 (Nível: 11) #75

vkorbes opened this issue Sep 30, 2020 · 2 comments

Comments

@vkorbes
Copy link
Owner

vkorbes commented Sep 30, 2020

Exercício: Capítulo 24, Exercício 3 (Nível: 11)

Link para o vídeo:

Use esta thread para compartilhar sua solução, discutir o exercício com os colegas e pedir ajuda caso tenha dificuldades!

@an4kein
Copy link

an4kein commented Mar 24, 2021

https://play.golang.org/p/d5zGffaC4CY

package main

import "fmt"

/* - Crie um struct "erroEspecial" que implemente a interface builtin.error.
- Crie uma função que tenha um valor do tipo error como parâmetro.
- Crie um valor do tipo "erroEspecial" e passe-o para a função da instrução anterior. */

type erroEspecial struct {
	teste string
}

func (e erroEspecial) Error() string {
	return "deu zicaaaa"
}

func erroComoParametro(e error) {
	fmt.Println("qualquer:", e.(erroEspecial).teste, "e no metodo error eu tenho:", e)

}

func main() {
	arg := erroEspecial{" precisooooooo aprender"}
	erroComoParametro(arg)
}

Output

qualquer:  precisooooooo aprender e no metodo error eu tenho: deu zicaaaa

Program exited.

@UdsonWillams
Copy link

package main

import (
	"fmt"
)

type erroEspecial struct {
	msg   string
	extra string
}

func (err erroEspecial) Error() string {
	return fmt.Sprintf("Algo inesperado aconteceu: %v | %v", err.msg, err.extra)
}

func errorType(err error) {
	fmt.Println("Funcão Error Type")
	fmt.Println(err.Error())
}

func main() {

	meuErro := erroEspecial{msg: "Olá, sou um erro criado!", extra: "Isso não deveria acontecer"}
	errorType(meuErro)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants