try, except, else e finally + Built-in Exceptions

This commit is contained in:
Luiz Otávio
2022-11-04 11:46:53 -03:00
parent 2a857eb25c
commit 9dd82e59af

17
aula94.py Normal file
View File

@@ -0,0 +1,17 @@
# try, except, else e finally
# https://docs.python.org/pt-br/3/library/exceptions.html#built-in-exceptions
try:
print('ABRIR ARQUIVO')
8/0
except ZeroDivisionError as e:
print(e.__class__.__name__)
print(e)
print('DIVIDIU ZERO')
except IndexError as error:
print('IndexError')
except (NameError, ImportError):
print('NameError, ImportError')
else:
print('Não deu erro')
finally:
print('FECHAR ARQUIVO')