homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: try/except block is both efficient and expensive?
Type: Stage: resolved
Components: Documentation Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, ezio.melotti, georg.brandl, python-dev, terry.reedy, tshepang
Priority: normal Keywords: patch

Created on 2012年03月14日 21:41 by tshepang, last changed 2022年04月11日 14:57 by admin. This issue is now closed.

Messages (6)
msg155798 - (view) Author: Tshepang Lekhonkhobe (tshepang) * Date: 2012年03月14日 21:41
In Doc/faq/design.rst, we got this text:
"A try/except block is extremely efficient. Actually catching an exception is expensive."
The 2 sentences appear contradictory.
msg155802 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2012年03月14日 21:44
What it's trying to say is that in case the operation in the "try" block succeeds there's almost no overhead, so it's very efficient. On the other hand, raising and then catching the error is expensive.
msg155803 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2012年03月14日 21:45
It could be reworded, yes.
msg156074 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2012年03月16日 20:08
I think it would be sufficient to add ' if no exceptions are raised' to the first sentence. The example that follows in the entry clarifies the implications of "cheap to try, expensive to catch".
msg156164 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012年03月17日 15:58
New changeset 9a7dcfbcf726 by Georg Brandl in branch '3.2':
Closes #14306: clarify expensiveness of try-except and update code snippet
http://hg.python.org/cpython/rev/9a7dcfbcf726 
msg156165 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012年03月17日 15:58
New changeset 7a93f6ee2ebc by Georg Brandl in branch '2.7':
Closes #14306: clarify expensiveness of try-except and update code snippet
http://hg.python.org/cpython/rev/7a93f6ee2ebc 
History
Date User Action Args
2022年04月11日 14:57:28adminsetgithub: 58514
2012年03月17日 15:58:55python-devsetmessages: + msg156165
2012年03月17日 15:58:16python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg156164

resolution: fixed
stage: resolved
2012年03月16日 20:08:32terry.reedysetkeywords: + patch
nosy: + terry.reedy
messages: + msg156074

2012年03月14日 21:45:12georg.brandlsetnosy: + georg.brandl
messages: + msg155803
2012年03月14日 21:44:21ezio.melottisetnosy: + ezio.melotti
messages: + msg155802
2012年03月14日 21:41:18tshepangcreate

AltStyle によって変換されたページ (->オリジナル) /