miroir de
https://github.com/PAPAMICA/Wiki-Tech.io.git
synchronisé 2024-09-19 06:05:09 +02:00
docs: update Scripting/Python/exceptions
Cette révision appartient à :
Parent
a3fe1d1636
révision
8bd3d465b0
1 fichiers modifiés avec 28 ajouts et 1 suppressions
|
@ -2,7 +2,7 @@
|
||||||
title: Python - Gérer les erreurs
|
title: Python - Gérer les erreurs
|
||||||
description:
|
description:
|
||||||
published: true
|
published: true
|
||||||
date: 2021-09-02T14:02:13.789Z
|
date: 2021-09-02T14:26:08.731Z
|
||||||
tags:
|
tags:
|
||||||
editor: markdown
|
editor: markdown
|
||||||
dateCreated: 2021-09-02T13:38:45.304Z
|
dateCreated: 2021-09-02T13:38:45.304Z
|
||||||
|
@ -46,3 +46,30 @@ for nb in numbers:
|
||||||
nombre = 2 resultat = 0.5
|
nombre = 2 resultat = 0.5
|
||||||
{.is-success}
|
{.is-success}
|
||||||
|
|
||||||
|
Nous constatons que pour le nombre "a" le script n'a pas cessé de fonctionner, et à éxecuté les actions demandées dans le "except"
|
||||||
|
|
||||||
|
## Exceptions créées par le développeur
|
||||||
|
```python
|
||||||
|
a = 0
|
||||||
|
b = 2
|
||||||
|
numbers = [a,b]
|
||||||
|
|
||||||
|
for nb in numbers:
|
||||||
|
try:
|
||||||
|
result = 1/nb
|
||||||
|
if(result < 1):
|
||||||
|
raise Exception('LowerOne')
|
||||||
|
else:
|
||||||
|
print("nombre = ", nb, "resultat = ", result)
|
||||||
|
|
||||||
|
except ZeroDivisionError:
|
||||||
|
print("ca ne fonctionne pas avec ", nb)
|
||||||
|
|
||||||
|
except Exception as error:
|
||||||
|
if(str(error) == "LowerOne"):
|
||||||
|
print("résultat inférieur à 1")
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Chargement…
Référencer dans un nouveau ticket