Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > fr.comp.lang.python > #3700

Gestion d'exceptions Python

Path csiph.com!weretis.net!feeder8.news.weretis.net!feeder1.feed.usenet.farm!feed.usenet.farm!border1.nntp.ams1.giganews.com!nntp.giganews.com!buffer1.nntp.ams1.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date Tue, 28 Dec 2021 08:14:44 -0600
Newsgroups fr.comp.lang.python
Subject Gestion d'exceptions Python
X-poster PEAR::Net_NNTP v1.5.0 (stable)
From zeuwi <nospam_weezpokips@gmail.com.invalid>
Content-Type text/plain; charset=windows-1252
Content-Transfer-Encoding 8bit
Organization !No_Organization!
Message-ID <gBCdnXXRa4BJhlb8nZ2dnUU7983NnZ2d@giganews.com> (permalink)
Date Tue, 28 Dec 2021 08:14:44 -0600
Lines 24
X-Usenet-Provider http://www.giganews.com
X-Trace sv3-8q82EJUUp9Qhc3frSkGKgjVDu6q36Qw1LGygVKiPCKSITOR55yPsZMYUotI5YjgNyda48QhfuplzHLV!hdKOJqQ3FvfksysLxClfasQ8wf4pK6+PKTPWgCVQCDEliDxTnBKKye/ZZGCu2G+/VxXMDaHPQUQm
X-Complaints-To abuse@giganews.com
X-DMCA-Notifications http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info Otherwise we will be unable to process your complaint properly
X-Postfilter 1.3.40
X-Original-Lines 21
X-Original-Bytes 1861
Xref csiph.com fr.comp.lang.python:3700

Show key headers only | View raw


Bonjour,

J'ai ce bout de code, j'ai levé une exception, mais je m'étonne de voir pourquoi
le code continue de tourner alors même que cette dernière lève une exception. 
Lors des tests dans l'interpréteur, le rentre volontairement une année négative,
une erreur est bien levée cependant j'ai le résultat qui ressort et m'indique
qu'il s'agit d'une année non bissextile par exemple. Est ce bien comme cela
qu'une exception doit fonctionner? 

année = input("e;veuillez saisir une année: "e;)

try:
	année = int(année)
	if année <= 0:
                raise ValueError("e;L'année saisie est négative ou nulle"e;)
except ValueError:
	print('Erreur lors de la conversion de l'année')

if année % 400 == 0 or (année % 4 == 0 and année % 100 !=0):
	print("e;Bisextile"e;)
else: 
	print("e;Non Bisextile"e;)

Merci pour votre aide
Cdt,

Back to fr.comp.lang.python | Previous | NextNext in thread | Find similar


Thread

Gestion d'exceptions Python zeuwi <nospam_weezpokips@gmail.com.invalid> - 2021-12-28 08:14 -0600
  Re: Gestion d'exceptions Python Alain Ketterlin <alain@universite-de-strasbourg.fr.invalid> - 2021-12-28 16:52 +0100
    Re: Gestion d'exceptions Python Olivier Miakinen <om+news@miakinen.net> - 2021-12-28 22:37 +0100
      Re: Gestion d'exceptions Python Alain Ketterlin <alain@universite-de-strasbourg.fr.invalid> - 2021-12-29 09:23 +0100

csiph-web