Skip to content

Commit

Permalink
1.20 - Implementação e asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
vbuxbaum committed Apr 3, 2021
1 parent b00d733 commit 60724de
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions 1_introducao/20_excecoes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class Divisor:
def divisao_except(a, b):
try:
if not b:
raise Exception("Divisão por 0")
return a / b
except Exception as erro:
return str(erro)

def divisao_raise(a, b):
if not b:
raise Exception("Divisão por 0, raise externo")
return a / b


if __name__ == "__main__":
assert Divisor.divisao_except(3, 2) == 1.5
assert Divisor.divisao_except(3, 0) == "Divisão por 0"

try:
Divisor.divisao_raise(3, 0)
except Exception as erro:
assert str(erro) == "Divisão por 0, raise externo", erro

0 comments on commit 60724de

Please sign in to comment.