Skip to content

Commit 59540dc

Browse files
committed
docs/usocket: Clarify exceptions used.
1 parent 0aa8314 commit 59540dc

1 file changed

Lines changed: 18 additions & 7 deletions

File tree

docs/library/usocket.rst

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ This module provides access to the BSD socket interface.
1010
See corresponding `CPython module <https://docs.python.org/3/library/socket.html>`_ for
1111
comparison.
1212

13+
.. admonition:: Difference to CPython
14+
:class: attention
15+
16+
CPython used to have a ``socket.error`` exception which is now deprecated,
17+
and is an alias of OSError. In MicroPython, use OSError directly.
18+
1319
Socket address format(s)
1420
------------------------
1521

@@ -51,13 +57,18 @@ Functions
5157
s = socket.socket()
5258
s.connect(socket.getaddrinfo('www.micropython.org', 80)[0][-1])
5359

54-
.. only:: port_wipy
55-
56-
Exceptions
57-
----------
58-
59-
.. data:: socket.error
60-
.. data:: socket.timeout
60+
.. admonition:: Difference to CPython
61+
:class: attention
62+
63+
CPython raises a ``socket.gaierror`` exception (OSError subclass) in case
64+
of error in this function. MicroPython doesn't have ``socket.gaierror``
65+
and raises OSError directly. Note that error numbers of ``getaddrinfo()``
66+
form a separate namespace and may not match error numbers from
67+
``uerrno`` module. To distinguish ``getaddrinfo()`` errors, they are
68+
represented by negative numbers, whereas standard system errors are
69+
positive numbers (error numbers are accessible using ``e.args[0]`` property
70+
from an exception object). The use of negative values is a provisional
71+
detail which may change in the future.
6172

6273
Constants
6374
---------

0 commit comments

Comments
 (0)