uerrno: Document alongside OSError.

These are meant to be used together, so document them in the same place along with a practical example.
This commit is contained in:
Laurens Valk
2021-07-19 15:03:10 +02:00
parent 2c32d093d0
commit e8d47ffca1
4 changed files with 40 additions and 16 deletions
+22 -4
View File
@@ -33,8 +33,6 @@ Exceptions and error codes
.. autoclass:: ubuiltins.NotImplementedError
.. autoclass:: ubuiltins.OSError
.. autoclass:: ubuiltins.OverflowError
.. autoclass:: ubuiltins.RuntimeError
@@ -51,8 +49,19 @@ Exceptions and error codes
.. autoclass:: ubuiltins.ZeroDivisionError
.. automodule:: uerrno
:no-members:
OSError
--------
.. autoclass:: ubuiltins.OSError
.. rubric:: uerrno module
.. module:: uerrno
The ``errno`` attribute of an ``OSError`` indicates why the exception was
raised. It has one of the following values, which can be imported from the
``uerrno`` module:
.. autodata:: uerrno.EAGAIN
@@ -73,3 +82,12 @@ Exceptions and error codes
.. autodata:: uerrno.ETIMEDOUT
.. autodata:: uerrno.errorcode
Examples
---------------------
Detect devices using ``OSError``
*****************************************
.. literalinclude::
../../../examples/micropython/oserror.py
+11
View File
@@ -0,0 +1,11 @@
from pybricks.pupdevices import Motor
from pybricks.parameters import Port
from uerrno import ENODEV
try:
my_motor = Motor(Port.A)
print("Detected a motor.")
except OSError as ex:
if ex.errno == ENODEV:
print("There is no motor this port.")
+6 -7
View File
@@ -967,15 +967,15 @@ class NotImplementedError(RuntimeError):
class OSError(Exception):
"""
This exception is raised when a system function returns a system-related
error, including I/O failures.
This exception is raised by the firmware, which is
the Operating System that runs on the hub. For example, it
raises an ``OSError`` if you call ``Motor(Port.A)`` when there is no
motor on port A.
"""
errno: _int
"""
A numeric error code.
Also see :mod:`uerrno`.
Specifies which kind of ``OSError`` occurred, as listed below.
"""
@@ -1010,8 +1010,7 @@ class SyntaxError(Exception):
class SystemExit(BaseException):
"""
This exception is raised when the stop button is pressed (on the hub or in
the IDE).
Raised when you press the stop button on the hub or in the Pybricks Code app.
"""
+1 -5
View File
@@ -61,9 +61,5 @@ The operation timed out.
errorcode: Dict[int, str]
"""
Dictionary mapping numeric error codes to strings with symbolic error
code (see above)::
>>> print(uerrno.errorcode[uerrno.EEXIST])
EEXIST
Dictionary that maps numeric error codes to strings with symbolic error code.
"""