Skip to content

Commit 34dcd14

Browse files
author
benjamin.peterson
committed
pretend exceptions don't exist a while longer
git-svn-id: http://svn.python.org/projects/python/trunk@67924 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 81cb8a0 commit 34dcd14

File tree

1 file changed

+6
-28
lines changed

1 file changed

+6
-28
lines changed

Doc/tutorial/controlflow.rst

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -169,42 +169,20 @@ required syntactically but the program requires no action. For example::
169169
... pass # Busy-wait for keyboard interrupt (Ctrl+C)
170170
...
171171

172-
This is commonly used for creating minimal classes such as exceptions, or
173-
for ignoring unwanted exceptions::
172+
This is commonly used for creating minimal classes::
174173

175-
>>> class ParserError(Exception):
174+
>>> class MyEmptyClass:
176175
... pass
177-
...
178-
>>> try:
179-
... import audioop
180-
... except ImportError:
181-
... pass
182-
...
176+
...
183177

184178
Another place :keyword:`pass` can be used is as a place-holder for a function or
185-
conditional body when you are working on new code, allowing you to keep
186-
thinking at a more abstract level. However, as :keyword:`pass` is silently
187-
ignored, a better choice may be to raise a :exc:`NotImplementedError`
188-
exception::
179+
conditional body when you are working on new code, allowing you to keep thinking
180+
at a more abstract level. The :keyword:`pass` is silently ignored::
189181

190182
>>> def initlog(*args):
191-
... raise NotImplementedError # Open logfile if not already open
192-
... if not logfp:
193-
... raise NotImplementedError # Set up dummy log back-end
194-
... raise NotImplementedError('Call log initialization handler')
183+
... pass # Remember to implement this!
195184
...
196185

197-
If :keyword:`pass` were used here and you later ran tests, they may fail
198-
without indicating why. Using :exc:`NotImplementedError` causes this code
199-
to raise an exception, telling you exactly where the incomplete code
200-
is. Note the two calling styles of the exceptions above.
201-
The first style, with no message but with an accompanying comment,
202-
lets you easily leave the comment when you remove the exception,
203-
which ideally would be a good description for
204-
the block of code the exception is a placeholder for. However, the
205-
third example, providing a message for the exception, will produce
206-
a more useful traceback.
207-
208186
.. _tut-functions:
209187

210188
Defining Functions

0 commit comments

Comments
 (0)