mirror of https://github.com/python/cpython
Improve description of PEP 3151
This commit is contained in:
parent
767c0a82ad
commit
01fd26c746
|
@ -113,40 +113,44 @@ PEP 3151: Reworking the OS and IO exception hierarchy
|
||||||
=====================================================
|
=====================================================
|
||||||
|
|
||||||
: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.
|
PEP written and implemented by Antoine Pitrou.
|
||||||
|
|
||||||
New subclasses of :exc:`OSError` exceptions:
|
The hierarchy of exceptions raised by operating system errors is now both
|
||||||
|
simplified and finer-grained.
|
||||||
|
|
||||||
* :exc:`BlockingIOError`
|
You don't have to worry anymore about choosing the appropriate exception
|
||||||
* :exc:`ChildProcessError`
|
type between :exc:`OSError`, :exc:`IOError`, :exc:`EnvironmentError`,
|
||||||
* :exc:`ConnectionError`
|
: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.
|
||||||
|
|
||||||
* :exc:`BrokenPipeError`
|
Also, it is now easier to catch a specific error condition. Instead of
|
||||||
* :exc:`ConnectionAbortedError`
|
inspecting the ``errno`` attribute (or ``args[0]``) for a particular
|
||||||
* :exc:`ConnectionRefusedError`
|
constant from the :mod:`errno` module, you can catch the adequate
|
||||||
* :exc:`ConnectionResetError`
|
:exc:`OSError` subclass. The available subclasses are the following:
|
||||||
|
|
||||||
* :exc:`FileExistsError`
|
* :exc:`BlockingIOError`
|
||||||
* :exc:`FileNotFoundError`
|
* :exc:`ChildProcessError`
|
||||||
* :exc:`InterruptedError`
|
* :exc:`ConnectionError`
|
||||||
* :exc:`IsADirectoryError`
|
* :exc:`FileExistsError`
|
||||||
* :exc:`NotADirectoryError`
|
* :exc:`FileNotFoundError`
|
||||||
* :exc:`PermissionError`
|
* :exc:`InterruptedError`
|
||||||
* :exc:`ProcessLookupError`
|
* :exc:`IsADirectoryError`
|
||||||
* :exc:`TimeoutError`
|
* :exc:`NotADirectoryError`
|
||||||
|
* :exc:`PermissionError`
|
||||||
|
* :exc:`ProcessLookupError`
|
||||||
|
* :exc:`TimeoutError`
|
||||||
|
|
||||||
The following exceptions have been merged into :exc:`OSError`:
|
And the :exc:`ConnectionError` itself has finer-grained subclasses:
|
||||||
|
|
||||||
* :exc:`EnvironmentError`
|
* :exc:`BrokenPipeError`
|
||||||
* :exc:`IOError`
|
* :exc:`ConnectionAbortedError`
|
||||||
* :exc:`WindowsError`
|
* :exc:`ConnectionRefusedError`
|
||||||
* :exc:`VMSError`
|
* :exc:`ConnectionResetError`
|
||||||
* :exc:`socket.error`
|
|
||||||
* :exc:`select.error`
|
|
||||||
* :exc:`mmap.error`
|
|
||||||
|
|
||||||
Thanks to the new exceptions, common usages of the :mod:`errno` can now be
|
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
|
from errno import ENOENT, EACCES, EPERM
|
||||||
|
|
||||||
|
@ -161,7 +165,8 @@ avoided. For example, the following code written for Python 3.2: ::
|
||||||
else:
|
else:
|
||||||
raise
|
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:
|
try:
|
||||||
with open("document.txt") as f:
|
with open("document.txt") as f:
|
||||||
|
|
Loading…
Reference in New Issue