Skip to content

Commit

Permalink
14.6 panic e recorver
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruteski committed Mar 27, 2024
1 parent 6671039 commit 37a4fc7
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions 14-funcoes_avacadas/14.6-panic_recover/panic_recover.go
Original file line number Diff line number Diff line change
@@ -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")

}

0 comments on commit 37a4fc7

Please sign in to comment.