(Parte 2) try e except para tratar exceções

This commit is contained in:
Luiz Otávio
2022-11-04 11:31:54 -03:00
parent db2d8aac0f
commit 2a857eb25c

View File

@@ -1,4 +1,4 @@
# (Parte1) try e except para tratar exceções
# (Parte 2) try e except para tratar exceções
# a = 18
# b = 0
# c = a / b
@@ -7,15 +7,18 @@ try:
a = 18
b = 0
# print(b[0])
print('Linha 1'[1000])
# print('Linha 1'[1000])
c = a / b
print('Linha 2')
except ZeroDivisionError:
print('Dividiu por zero.')
except ZeroDivisionError as e:
print(e.__class__.__name__)
print(e)
except NameError:
print('Nome b não está definido')
except (TypeError, IndexError):
except (TypeError, IndexError) as error:
print('TypeError + IndexError')
print('MSG:', error)
print('Nome:', error.__class__.__name__)
except Exception:
print('ERRO DESCONHECIDO.')