From 37a4fc77a90359897dd53002f4d4a0cb5c9d60ff Mon Sep 17 00:00:00 2001 From: Lincoln Ruteski Date: Wed, 27 Mar 2024 16:59:43 -0300 Subject: [PATCH] 14.6 panic e recorver --- .../14.6-panic_recover/panic_recover.go | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 14-funcoes_avacadas/14.6-panic_recover/panic_recover.go diff --git a/14-funcoes_avacadas/14.6-panic_recover/panic_recover.go b/14-funcoes_avacadas/14.6-panic_recover/panic_recover.go new file mode 100644 index 0000000..1159c35 --- /dev/null +++ b/14-funcoes_avacadas/14.6-panic_recover/panic_recover.go @@ -0,0 +1,30 @@ +package main + +import "fmt" + +func recuperaExecucao() { + if r := recover(); r != nil { + fmt.Println("Tentativa de recuperar a execução") + } +} + +func alunoEstaAprovado(n1, n2 float64) bool { + defer recuperaExecucao() + + media := (n1 + n2) / 2 + + if media > 6 { + return true + } else if media < 6 { + return false + } + + panic("A MEDIA E EXATAMENTE 6!") +} + +func main() { + + fmt.Println(alunoEstaAprovado(6, 6)) + fmt.Println("Pós execução") + +}