-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaula145.py
More file actions
26 lines (22 loc) · 704 Bytes
/
Copy pathaula145.py
File metadata and controls
26 lines (22 loc) · 704 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Criando Exceptions em Python Orientado a Objetos
# Para criar uma Exception em Python, você só
# precisa herdar de alguma exceção da linguagem.
# A recomendação da doc é herdar de Exception.
# https://docs.python.org/3/library/exceptions.html
# Criando exceções (comum colocar Error ao final)
# Levantando (raise) / Lançando (throw) exceções
# Relançando exceções
# Adicionando notas em exceções (3.11.0)
class MyError(Exception):
...
class OtherError(Exception):
...
def levantar():
exception_ = MyError('a', 'b', 'c')
raise exception_
try:
levantar()
except MyError as e:
print(e)
exception_ = MyError('VOU LANÇAR OUTRA')
raise exception_ from e