Skip to content

Exceptions

raspbot.exceptions

All exceptions raised by the raspbot library are subclasses of RaspbotError.


Hierarchy

1
2
3
4
5
6
Exception
 └── RaspbotError
      ├── I2CError
      ├── DeviceNotFoundError
      ├── OLEDError
      └── HardwareNotReadyError

RaspbotError

class RaspbotError(Exception): ...

Base exception for all raspbot errors. Catch this to handle any library error in one place.

1
2
3
4
5
6
7
from raspbot.exceptions import RaspbotError

try:
    with Robot() as bot:
        ...
except RaspbotError as e:
    print("Hardware error:", e)

I2CError

1
2
3
4
class I2CError(RaspbotError):
    def __init__(self, operation: str, cause: BaseException | None = None) -> None: ...
    operation: str
    cause: BaseException | None

Raised when an I2C read or write operation fails.

Attribute Description
operation Short description of the I2C operation that failed
cause The underlying exception, if any

DeviceNotFoundError

1
2
3
4
class DeviceNotFoundError(RaspbotError):
    def __init__(self, address: int, bus: int) -> None: ...
    address: int
    bus: int

Raised when the I2C device cannot be found on the bus (e.g. robot not powered on).

Attribute Description
address I2C address that was not found
bus Linux I2C bus number

OLEDError

class OLEDError(RaspbotError): ...

Raised when the OLED display cannot be initialised or driven (e.g. begin() was not called before add_line()).


HardwareNotReadyError

class HardwareNotReadyError(RaspbotError): ...

Raised when hardware is used before it has been initialised.


Importing exceptions

1
2
3
4
5
6
7
from raspbot.exceptions import (
    RaspbotError,
    I2CError,
    DeviceNotFoundError,
    OLEDError,
    HardwareNotReadyError,
)

All exceptions are also re-exported from the top-level raspbot package:

from raspbot import RaspbotError, I2CError, DeviceNotFoundError

See also