diff options
author | Benjamin Peterson <benjamin@python.org> | 2008-12-24 16:10:05 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2008-12-24 16:10:05 (GMT) |
commit | 42d19e6a2c1a3fcaa80b2315ea2c9e993b61a315 (patch) | |
tree | 7edd8a3810f60f97542c46e441a997671ecdf7e7 | |
parent | 54686e3c2981a18521db088ffc16d5f4e5983e75 (diff) | |
download | cpython-42d19e6a2c1a3fcaa80b2315ea2c9e993b61a315.zip cpython-42d19e6a2c1a3fcaa80b2315ea2c9e993b61a315.tar.gz cpython-42d19e6a2c1a3fcaa80b2315ea2c9e993b61a315.tar.bz2 |
pretend exceptions don't exist a while longer
-rw-r--r-- | Doc/tutorial/controlflow.rst | 34 |
1 files changed, 6 insertions, 28 deletions
diff --git a/Doc/tutorial/controlflow.rst b/Doc/tutorial/controlflow.rst index f57e9e9..afc19e9 100644 --- a/Doc/tutorial/controlflow.rst +++ b/Doc/tutorial/controlflow.rst @@ -169,42 +169,20 @@ required syntactically but the program requires no action. For example:: ... pass # Busy-wait for keyboard interrupt (Ctrl+C) ... -This is commonly used for creating minimal classes such as exceptions, or -for ignoring unwanted exceptions:: +This is commonly used for creating minimal classes:: - >>> class ParserError(Exception): + >>> class MyEmptyClass: ... pass - ... - >>> try: - ... import audioop - ... except ImportError: - ... pass - ... + ... Another place :keyword:`pass` can be used is as a place-holder for a function or -conditional body when you are working on new code, allowing you to keep -thinking at a more abstract level. However, as :keyword:`pass` is silently -ignored, a better choice may be to raise a :exc:`NotImplementedError` -exception:: +conditional body when you are working on new code, allowing you to keep thinking +at a more abstract level. The :keyword:`pass` is silently ignored:: >>> def initlog(*args): - ... raise NotImplementedError # Open logfile if not already open - ... if not logfp: - ... raise NotImplementedError # Set up dummy log back-end - ... raise NotImplementedError('Call log initialization handler') + ... pass # Remember to implement this! ... -If :keyword:`pass` were used here and you later ran tests, they may fail -without indicating why. Using :exc:`NotImplementedError` causes this code -to raise an exception, telling you exactly where the incomplete code -is. Note the two calling styles of the exceptions above. -The first style, with no message but with an accompanying comment, -lets you easily leave the comment when you remove the exception, -which ideally would be a good description for -the block of code the exception is a placeholder for. However, the -third example, providing a message for the exception, will produce -a more useful traceback. - .. _tut-functions: Defining Functions |