# 24. 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 the obvious:

    from gpiozero import *

    led = PWMLED(17)
    try:
        led.value = 2
    except ValueError:
        print('Bad value specified')

## 24.1. Errors

exception `gpiozero.``GPIOZeroError`

  Bases: `Exception`

  Base class for all exceptions in GPIO Zero

exception `gpiozero.``DeviceClosed`

  Bases: `gpiozero.exc.GPIOZeroError`

  Error raised when an operation is attempted on a closed device

exception `gpiozero.``BadEventHandler`

  Bases: `gpiozero.exc.GPIOZeroError`, `ValueError`

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

exception `gpiozero.``BadWaitTime`

  Bases: `gpiozero.exc.GPIOZeroError`, `ValueError`

  Error raised when an invalid wait time is specified

exception `gpiozero.``BadQueueLen`

  Bases: `gpiozero.exc.GPIOZeroError`, `ValueError`

  Error raised when non-positive queue length is specified

exception `gpiozero.``BadPinFactory`

  Bases: `gpiozero.exc.GPIOZeroError`, `ImportError`

  Error raised when an unknown pin factory name is specified

exception `gpiozero.``ZombieThread`

  Bases: `gpiozero.exc.GPIOZeroError`, `RuntimeError`

  Error raised when a thread fails to die within a given timeout

exception `gpiozero.``CompositeDeviceError`

  Bases: `gpiozero.exc.GPIOZeroError`

  Base class for errors specific to the CompositeDevice hierarchy

exception `gpiozero.``CompositeDeviceBadName`

  Bases: `gpiozero.exc.CompositeDeviceError`, `ValueError`

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

exception `gpiozero.``CompositeDeviceBadOrder`

  Bases: `gpiozero.exc.CompositeDeviceError`, `ValueError`

  Error raised when a composite device is constructed with an incomplete order

exception `gpiozero.``CompositeDeviceBadDevice`

  Bases: `gpiozero.exc.CompositeDeviceError`, `ValueError`

  Error raised when a composite device is constructed with an object that doesn’t inherit from `Device`

exception `gpiozero.``EnergenieSocketMissing`

  Bases: `gpiozero.exc.CompositeDeviceError`, `ValueError`

  Error raised when socket number is not specified

exception `gpiozero.``EnergenieBadSocket`

  Bases: `gpiozero.exc.CompositeDeviceError`, `ValueError`

  Error raised when an invalid socket number is passed to `Energenie`

exception `gpiozero.``SPIError`

  Bases: `gpiozero.exc.GPIOZeroError`

  Base class for errors related to the SPI implementation

exception `gpiozero.``SPIBadArgs`

  Bases: `gpiozero.exc.SPIError`, `ValueError`

  Error raised when invalid arguments are given while constructing `SPIDevice`

exception `gpiozero.``SPIBadChannel`

  Bases: `gpiozero.exc.SPIError`, `ValueError`

  Error raised when an invalid channel is given to an `AnalogInputDevice`

exception `gpiozero.``SPIFixedClockMode`

  Bases: `gpiozero.exc.SPIError`, `AttributeError`

  Error raised when the SPI clock mode cannot be changed

exception `gpiozero.``SPIInvalidClockMode`

  Bases: `gpiozero.exc.SPIError`, `ValueError`

  Error raised when an invalid clock mode is given to an SPI implementation

exception `gpiozero.``SPIFixedBitOrder`

  Bases: `gpiozero.exc.SPIError`, `AttributeError`

  Error raised when the SPI bit-endianness cannot be changed

exception `gpiozero.``SPIFixedSelect`

  Bases: `gpiozero.exc.SPIError`, `AttributeError`

  Error raised when the SPI select polarity cannot be changed

exception `gpiozero.``SPIFixedWordSize`

  Bases: `gpiozero.exc.SPIError`, `AttributeError`

  Error raised when the number of bits per word cannot be changed

exception `gpiozero.``SPIInvalidWordSize`

  Bases: `gpiozero.exc.SPIError`, `ValueError`

  Error raised when an invalid (out of range) number of bits per word is specified

exception `gpiozero.``GPIODeviceError`

  Bases: `gpiozero.exc.GPIOZeroError`

  Base class for errors specific to the GPIODevice hierarchy

exception `gpiozero.``GPIODeviceClosed`

  Bases: `gpiozero.exc.GPIODeviceError`, `gpiozero.exc.DeviceClosed`

  Deprecated descendent of `DeviceClosed`

exception `gpiozero.``GPIOPinInUse`

  Bases: `gpiozero.exc.GPIODeviceError`

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

exception `gpiozero.``GPIOPinMissing`

  Bases: `gpiozero.exc.GPIODeviceError`, `ValueError`

  Error raised when a pin specification is not given

exception `gpiozero.``InputDeviceError`

  Bases: `gpiozero.exc.GPIODeviceError`

  Base class for errors specific to the InputDevice hierarchy

exception `gpiozero.``OutputDeviceError`

  Bases: `gpiozero.exc.GPIODeviceError`

  Base class for errors specified to the OutputDevice hierarchy

exception `gpiozero.``OutputDeviceBadValue`

  Bases: `gpiozero.exc.OutputDeviceError`, `ValueError`

  Error raised when `value` is set to an invalid value

exception `gpiozero.``PinError`

  Bases: `gpiozero.exc.GPIOZeroError`

  Base class for errors related to pin implementations

exception `gpiozero.``PinInvalidFunction`

  Bases: `gpiozero.exc.PinError`, `ValueError`

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

exception `gpiozero.``PinInvalidState`

  Bases: `gpiozero.exc.PinError`, `ValueError`

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

exception `gpiozero.``PinInvalidPull`

  Bases: `gpiozero.exc.PinError`, `ValueError`

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

exception `gpiozero.``PinInvalidEdges`

  Bases: `gpiozero.exc.PinError`, `ValueError`

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

exception `gpiozero.``PinInvalidBounce`

  Bases: `gpiozero.exc.PinError`, `ValueError`

  Error raised when attempting to assign an invalid bounce time to a pin

exception `gpiozero.``PinSetInput`

  Bases: `gpiozero.exc.PinError`, `AttributeError`

  Error raised when attempting to set a read-only pin

exception `gpiozero.``PinFixedPull`

  Bases: `gpiozero.exc.PinError`, `AttributeError`

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

exception `gpiozero.``PinEdgeDetectUnsupported`

  Bases: `gpiozero.exc.PinError`, `AttributeError`

  Error raised when attempting to use edge detection on unsupported pins

exception `gpiozero.``PinUnsupported`

  Bases: `gpiozero.exc.PinError`, `NotImplementedError`

  Error raised when attempting to obtain a pin interface on unsupported pins

exception `gpiozero.``PinSPIUnsupported`

  Bases: `gpiozero.exc.PinError`, `NotImplementedError`

  Error raised when attempting to obtain an SPI interface on unsupported pins

exception `gpiozero.``PinPWMError`

  Bases: `gpiozero.exc.PinError`

  Base class for errors related to PWM implementations

exception `gpiozero.``PinPWMUnsupported`

  Bases: `gpiozero.exc.PinPWMError`, `AttributeError`

  Error raised when attempting to activate PWM on unsupported pins

exception `gpiozero.``PinPWMFixedValue`

  Bases: `gpiozero.exc.PinPWMError`, `AttributeError`

  Error raised when attempting to initialize PWM on an input pin

exception `gpiozero.``PinUnknownPi`

  Bases: `gpiozero.exc.PinError`, `RuntimeError`

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

exception `gpiozero.``PinMultiplePins`

  Bases: `gpiozero.exc.PinError`, `RuntimeError`

  Error raised when multiple pins support the requested function

exception `gpiozero.``PinNoPins`

  Bases: `gpiozero.exc.PinError`, `RuntimeError`

  Error raised when no pins support the requested function

exception `gpiozero.``PinInvalidPin`

  Bases: `gpiozero.exc.PinError`, `ValueError`

  Error raised when an invalid pin specification is provided

## 24.2. Warnings

exception `gpiozero.``GPIOZeroWarning`

  Bases: `Warning`

  Base class for all warnings in GPIO Zero

exception `gpiozero.``DistanceSensorNoEcho`

  Bases: `gpiozero.exc.GPIOZeroWarning`

  Warning raised when the distance sensor sees no echo at all

exception `gpiozero.``SPIWarning`

  Bases: `gpiozero.exc.GPIOZeroWarning`

  Base class for warnings related to the SPI implementation

exception `gpiozero.``SPISoftwareFallback`

  Bases: `gpiozero.exc.SPIWarning`

  Warning raised when falling back to the SPI software implementation

exception `gpiozero.``PinWarning`

  Bases: `gpiozero.exc.GPIOZeroWarning`

  Base class for warnings related to pin implementations

exception `gpiozero.``PinFactoryFallback`

  Bases: `gpiozero.exc.PinWarning`

  Warning raised when a default pin factory fails to load and a fallback is tried

exception `gpiozero.``PinNonPhysical`

  Bases: `gpiozero.exc.PinWarning`

  Warning raised when a non-physical pin is specified in a constructor

exception `gpiozero.``ThresholdOutOfRange`

  Bases: `gpiozero.exc.GPIOZeroWarning`

  Warning raised when a threshold is out of range specified by min and max values

exception `gpiozero.``CallbackSetToNone`

  Bases: `gpiozero.exc.GPIOZeroWarning`

  Warning raised when a callback is set to None when its previous value was None