21. API - Exceptions¶
The following exceptions are defined by GPIO Zero. Please note that multiple inheritance is heavily used in the exception hierarchy to make testing for exceptions easier. For example, to capture any exception generated by GPIO Zero’s code:
from gpiozero import *
led = PWMLED(17)
try:
led.value = 2
except GPIOZeroError:
print('A GPIO Zero error occurred')
Since all GPIO Zero’s exceptions descend from GPIOZeroError
, this will
work. However, certain specific errors have multiple parents. For example, in
the case that an out of range value is passed to OutputDevice.value
you
would expect a ValueError
to be raised. In fact, a
OutputDeviceBadValue
error will be raised. However, note that this
descends from both GPIOZeroError
(indirectly) and from ValueError
so you can still do:
from gpiozero import *
led = PWMLED(17)
try:
led.value = 2
except ValueError:
print('Bad value specified')
21.1. Errors¶
-
exception
gpiozero.
DeviceClosed
[source]¶ Error raised when an operation is attempted on a closed device
-
exception
gpiozero.
BadEventHandler
[source]¶ Error raised when an event handler with an incompatible prototype is specified
-
exception
gpiozero.
CompositeDeviceError
[source]¶ Base class for errors specific to the CompositeDevice hierarchy
-
exception
gpiozero.
CompositeDeviceBadName
[source]¶ Error raised when a composite device is constructed with a reserved name
-
exception
gpiozero.
EnergenieBadSocket
[source]¶ Error raised when an invalid socket number is passed to
Energenie
-
exception
gpiozero.
SPIBadArgs
[source]¶ Error raised when invalid arguments are given while constructing
SPIDevice
-
exception
gpiozero.
SPIBadChannel
[source]¶ Error raised when an invalid channel is given to an
AnalogInputDevice
-
exception
gpiozero.
SPIFixedClockMode
[source]¶ Error raised when the SPI clock mode cannot be changed
-
exception
gpiozero.
SPIInvalidClockMode
[source]¶ Error raised when an invalid clock mode is given to an SPI implementation
-
exception
gpiozero.
SPIFixedBitOrder
[source]¶ Error raised when the SPI bit-endianness cannot be changed
-
exception
gpiozero.
SPIFixedSelect
[source]¶ Error raised when the SPI select polarity cannot be changed
-
exception
gpiozero.
SPIFixedWordSize
[source]¶ Error raised when the number of bits per word cannot be changed
-
exception
gpiozero.
SPIInvalidWordSize
[source]¶ Error raised when an invalid (out of range) number of bits per word is specified
-
exception
gpiozero.
GPIODeviceError
[source]¶ Base class for errors specific to the GPIODevice hierarchy
-
exception
gpiozero.
GPIODeviceClosed
[source]¶ Deprecated descendent of
DeviceClosed
-
exception
gpiozero.
GPIOPinInUse
[source]¶ Error raised when attempting to use a pin already in use by another device
-
exception
gpiozero.
InputDeviceError
[source]¶ Base class for errors specific to the InputDevice hierarchy
-
exception
gpiozero.
OutputDeviceError
[source]¶ Base class for errors specified to the OutputDevice hierarchy
-
exception
gpiozero.
PinInvalidFunction
[source]¶ Error raised when attempting to change the function of a pin to an invalid value
-
exception
gpiozero.
PinInvalidState
[source]¶ Error raised when attempting to assign an invalid state to a pin
-
exception
gpiozero.
PinInvalidPull
[source]¶ Error raised when attempting to assign an invalid pull-up to a pin
-
exception
gpiozero.
PinInvalidEdges
[source]¶ Error raised when attempting to assign an invalid edge detection to a pin
-
exception
gpiozero.
PinInvalidBounce
[source]¶ Error raised when attempting to assign an invalid bounce time to a pin
-
exception
gpiozero.
PinFixedPull
[source]¶ Error raised when attempting to set the pull of a pin with fixed pull-up
-
exception
gpiozero.
PinEdgeDetectUnsupported
[source]¶ Error raised when attempting to use edge detection on unsupported pins
-
exception
gpiozero.
PinUnsupported
[source]¶ Error raised when attempting to obtain a pin interface on unsupported pins
-
exception
gpiozero.
PinSPIUnsupported
[source]¶ Error raised when attempting to obtain an SPI interface on unsupported pins
-
exception
gpiozero.
PinPWMUnsupported
[source]¶ Error raised when attempting to activate PWM on unsupported pins
-
exception
gpiozero.
PinPWMFixedValue
[source]¶ Error raised when attempting to initialize PWM on an input pin
-
exception
gpiozero.
PinUnknownPi
[source]¶ Error raised when gpiozero doesn’t recognize a revision of the Pi