From 2a857eb25c6297902d5445ce627b55f3e554eff5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luiz=20Ot=C3=A1vio?= Date: Fri, 4 Nov 2022 11:31:54 -0300 Subject: [PATCH] =?UTF-8?q?(Parte=202)=20try=20e=20except=20para=20tratar?= =?UTF-8?q?=20exce=C3=A7=C3=B5es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- aula93.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/aula93.py b/aula93.py index 37d5439..b3acc2e 100644 --- a/aula93.py +++ b/aula93.py @@ -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.')