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')

Errors

exception gpiozero.GPIOZeroError

Base class for all exceptions in GPIO Zero

exception gpiozero.DeviceClosed

Error raised when an operation is attempted on a closed device

exception gpiozero.BadEventHandler

Error raised when an event handler with an incompatible prototype is specified

exception gpiozero.BadQueueLen

Error raised when non-positive queue length is specified

exception gpiozero.BadWaitTime

Error raised when an invalid wait time is specified

exception gpiozero.CompositeDeviceError

Base class for errors specific to the CompositeDevice hierarchy

exception gpiozero.CompositeDeviceBadName

Error raised when a composite device is constructed with a reserved name

exception gpiozero.EnergenieSocketMissing

Error raised when socket number is not specified

exception gpiozero.EnergenieBadSocket

Error raised when an invalid socket number is passed to Energenie

exception gpiozero.SPIError

Base class for errors related to the SPI implementation

exception gpiozero.SPIBadArgs

Error raised when invalid arguments are given while constructing SPIDevice

exception gpiozero.GPIODeviceError

Base class for errors specific to the GPIODevice hierarchy

exception gpiozero.GPIODeviceClosed

Deprecated descendent of DeviceClosed

exception gpiozero.GPIOPinInUse

Error raised when attempting to use a pin already in use by another device

exception gpiozero.GPIOPinMissing

Error raised when a pin number is not specified

exception gpiozero.InputDeviceError

Base class for errors specific to the InputDevice hierarchy

exception gpiozero.OutputDeviceError

Base class for errors specified to the OutputDevice hierarchy

exception gpiozero.OutputDeviceBadValue

Error raised when value is set to an invalid value

exception gpiozero.PinError

Base class for errors related to pin implementations

exception gpiozero.PinInvalidFunction

Error raised when attempting to change the function of a pin to an invalid value

exception gpiozero.PinInvalidState

Error raised when attempting to assign an invalid state to a pin

exception gpiozero.PinInvalidPull

Error raised when attempting to assign an invalid pull-up to a pin

exception gpiozero.PinInvalidEdges

Error raised when attempting to assign an invalid edge detection to a pin

exception gpiozero.PinSetInput

Error raised when attempting to set a read-only pin

exception gpiozero.PinFixedPull

Error raised when attempting to set the pull of a pin with fixed pull-up

exception gpiozero.PinEdgeDetectUnsupported

Error raised when attempting to use edge detection on unsupported pins

exception gpiozero.PinPWMError

Base class for errors related to PWM implementations

exception gpiozero.PinPWMUnsupported

Error raised when attempting to activate PWM on unsupported pins

exception gpiozero.PinPWMFixedValue

Error raised when attempting to initialize PWM on an input pin

exception gpiozero.PinMultiplePins

Error raised when multiple pins support the requested function

exception gpiozero.PinNoPins

Error raised when no pins support the requested function

exception gpiozero.PinUnknownPi

Error raised when gpiozero doesn’t recognize a revision of the Pi

Warnings

exception gpiozero.GPIOZeroWarning

Base class for all warnings in GPIO Zero

exception gpiozero.SPIWarning

Base class for warnings related to the SPI implementation

exception gpiozero.SPISoftwareFallback

Warning raised when falling back to the software implementation

Table Of Contents

Previous topic

Pins

Next topic

Changelog

This Page