From 8bd3d465b018c41b981731dabbc64b6a18d15ae5 Mon Sep 17 00:00:00 2001 From: Maxime Mourier Date: Thu, 2 Sep 2021 14:26:10 +0000 Subject: [PATCH] docs: update Scripting/Python/exceptions --- Scripting/Python/exceptions.md | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/Scripting/Python/exceptions.md b/Scripting/Python/exceptions.md index ed741e2..6005ef6 100644 --- a/Scripting/Python/exceptions.md +++ b/Scripting/Python/exceptions.md @@ -2,7 +2,7 @@ title: Python - Gérer les erreurs description: published: true -date: 2021-09-02T14:02:13.789Z +date: 2021-09-02T14:26:08.731Z tags: editor: markdown dateCreated: 2021-09-02T13:38:45.304Z @@ -45,4 +45,31 @@ for nb in numbers: > ca ne fonctionne pas avec 0 nombre = 2 resultat = 0.5 {.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") +``` + + +