(Parte 2) try e except para tratar exceções
This commit is contained in:
13
aula93.py
13
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
|
# a = 18
|
||||||
# b = 0
|
# b = 0
|
||||||
# c = a / b
|
# c = a / b
|
||||||
@@ -7,15 +7,18 @@ try:
|
|||||||
a = 18
|
a = 18
|
||||||
b = 0
|
b = 0
|
||||||
# print(b[0])
|
# print(b[0])
|
||||||
print('Linha 1'[1000])
|
# print('Linha 1'[1000])
|
||||||
c = a / b
|
c = a / b
|
||||||
print('Linha 2')
|
print('Linha 2')
|
||||||
except ZeroDivisionError:
|
except ZeroDivisionError as e:
|
||||||
print('Dividiu por zero.')
|
print(e.__class__.__name__)
|
||||||
|
print(e)
|
||||||
except NameError:
|
except NameError:
|
||||||
print('Nome b não está definido')
|
print('Nome b não está definido')
|
||||||
except (TypeError, IndexError):
|
except (TypeError, IndexError) as error:
|
||||||
print('TypeError + IndexError')
|
print('TypeError + IndexError')
|
||||||
|
print('MSG:', error)
|
||||||
|
print('Nome:', error.__class__.__name__)
|
||||||
except Exception:
|
except Exception:
|
||||||
print('ERRO DESCONHECIDO.')
|
print('ERRO DESCONHECIDO.')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user