diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2011-10-23 22:07:02 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2011-10-23 22:07:02 (GMT) |
commit | 01fd26c7463483a9ce021606eb4e03096ecdfafd (patch) | |
tree | 989051bbe748b24f2ff28710f6b4ec87ae9fc8c2 /Doc/whatsnew/3.3.rst | |
parent | 767c0a82adb240db69cba2dc2bd8bc0ada095c96 (diff) | |
download | cpython-01fd26c7463483a9ce021606eb4e03096ecdfafd.zip cpython-01fd26c7463483a9ce021606eb4e03096ecdfafd.tar.gz cpython-01fd26c7463483a9ce021606eb4e03096ecdfafd.tar.bz2 |
Improve description of PEP 3151
Diffstat (limited to 'Doc/whatsnew/3.3.rst')
-rw-r--r-- | Doc/whatsnew/3.3.rst | 71 |
1 files changed, 38 insertions, 33 deletions
diff --git a/Doc/whatsnew/3.3.rst b/Doc/whatsnew/3.3.rst index 78fae2f..ce47608 100644 --- a/Doc/whatsnew/3.3.rst +++ b/Doc/whatsnew/3.3.rst @@ -113,40 +113,44 @@ PEP 3151: Reworking the OS and IO exception hierarchy ===================================================== :pep:`3151` - Reworking the OS and IO exception hierarchy -PEP written and implemented by Antoine Pitrou. - -New subclasses of :exc:`OSError` exceptions: - - * :exc:`BlockingIOError` - * :exc:`ChildProcessError` - * :exc:`ConnectionError` - - * :exc:`BrokenPipeError` - * :exc:`ConnectionAbortedError` - * :exc:`ConnectionRefusedError` - * :exc:`ConnectionResetError` - - * :exc:`FileExistsError` - * :exc:`FileNotFoundError` - * :exc:`InterruptedError` - * :exc:`IsADirectoryError` - * :exc:`NotADirectoryError` - * :exc:`PermissionError` - * :exc:`ProcessLookupError` - * :exc:`TimeoutError` - -The following exceptions have been merged into :exc:`OSError`: - - * :exc:`EnvironmentError` - * :exc:`IOError` - * :exc:`WindowsError` - * :exc:`VMSError` - * :exc:`socket.error` - * :exc:`select.error` - * :exc:`mmap.error` + PEP written and implemented by Antoine Pitrou. + +The hierarchy of exceptions raised by operating system errors is now both +simplified and finer-grained. + +You don't have to worry anymore about choosing the appropriate exception +type between :exc:`OSError`, :exc:`IOError`, :exc:`EnvironmentError`, +:exc:`WindowsError`, :exc:`mmap.error`, :exc:`socket.error` or +:exc:`select.error`. All these exception types are now only one: +:exc:`OSError`. The other names are kept as aliases for compatibility +reasons. + +Also, it is now easier to catch a specific error condition. Instead of +inspecting the ``errno`` attribute (or ``args[0]``) for a particular +constant from the :mod:`errno` module, you can catch the adequate +:exc:`OSError` subclass. The available subclasses are the following: + +* :exc:`BlockingIOError` +* :exc:`ChildProcessError` +* :exc:`ConnectionError` +* :exc:`FileExistsError` +* :exc:`FileNotFoundError` +* :exc:`InterruptedError` +* :exc:`IsADirectoryError` +* :exc:`NotADirectoryError` +* :exc:`PermissionError` +* :exc:`ProcessLookupError` +* :exc:`TimeoutError` + +And the :exc:`ConnectionError` itself has finer-grained subclasses: + +* :exc:`BrokenPipeError` +* :exc:`ConnectionAbortedError` +* :exc:`ConnectionRefusedError` +* :exc:`ConnectionResetError` Thanks to the new exceptions, common usages of the :mod:`errno` can now be -avoided. For example, the following code written for Python 3.2: :: +avoided. For example, the following code written for Python 3.2:: from errno import ENOENT, EACCES, EPERM @@ -161,7 +165,8 @@ avoided. For example, the following code written for Python 3.2: :: else: raise -can now be written without the :mod:`errno` import: :: +can now be written without the :mod:`errno` import and without manual +inspection of exception attributes:: try: with open("document.txt") as f: |