13. API - Exceptions¶
All exceptions defined by picamera are listed in this section. All exception
classes utilize multiple inheritance in order to make testing for exception
types more intuitive. For example, PiCameraValueError derives from both
PiCameraError and ValueError. Hence it will be caught by blocks
intended to catch any error specific to the picamera library:
try:
camera.brightness = int(some_user_value)
except PiCameraError:
print('Something went wrong with the camera')
Or by blocks intended to catch value errors:
try:
camera.contrast = int(some_user_value)
except ValueError:
print('Invalid value')
13.1. Warnings¶
-
exception
picamera.PiCameraDeprecated[source]¶ Bases:
picamera.exc.PiCameraWarning,DeprecationWarningRaised when deprecated functionality in picamera is used.
-
exception
picamera.PiCameraFallback[source]¶ Bases:
picamera.exc.PiCameraWarning,RuntimeWarningRaised when picamera has to fallback on old functionality.
-
exception
picamera.PiCameraResizerEncoding[source]¶ Bases:
picamera.exc.PiCameraWarning,RuntimeWarningRaised when picamera uses a resizer purely for encoding purposes.
-
exception
picamera.PiCameraAlphaStripping[source]¶ Bases:
picamera.exc.PiCameraWarning,RuntimeWarningRaised when picamera does alpha-byte stripping.
13.2. Exceptions¶
-
exception
picamera.PiCameraValueError[source]¶ Bases:
picamera.exc.PiCameraError,ValueErrorRaised when an invalid value is fed to a
PiCameraobject.
-
exception
picamera.PiCameraRuntimeError[source]¶ Bases:
picamera.exc.PiCameraError,RuntimeErrorRaised when an invalid sequence of operations is attempted with a
PiCameraobject.
-
exception
picamera.PiCameraClosed[source]¶ Bases:
picamera.exc.PiCameraRuntimeErrorRaised when a method is called on a camera which has already been closed.
-
exception
picamera.PiCameraNotRecording[source]¶ Bases:
picamera.exc.PiCameraRuntimeErrorRaised when
stop_recording()orsplit_recording()are called against a port which has no recording active.
-
exception
picamera.PiCameraAlreadyRecording[source]¶ Bases:
picamera.exc.PiCameraRuntimeErrorRaised when
start_recording()orrecord_sequence()are called against a port which already has an active recording.
-
exception
picamera.PiCameraMMALError(status, prefix='')[source]¶ Bases:
picamera.exc.PiCameraErrorRaised when an MMAL operation fails for whatever reason.
-
exception
picamera.PiCameraPortDisabled(msg)[source]¶ Bases:
picamera.exc.PiCameraMMALErrorRaised when attempting a buffer operation on a disabled port.
This exception is intended for the common use-case of attempting to get or send a buffer just when a component is shutting down (e.g. at script teardown) and simplifies the trivial response (ignore the error and shut down quietly). For example:
def _callback(self, port, buf): try: buf = self.outputs[0].get_buffer(False) except PiCameraPortDisabled: return True # shutting down # ...
13.3. Functions¶
-
picamera.mmal_check(status, prefix='')[source]¶ Checks the return status of an mmal call and raises an exception on failure.
The status parameter is the result of an MMAL call. If status is anything other than MMAL_SUCCESS, a
PiCameraMMALErrorexception is raised. The optional prefix parameter specifies a prefix message to place at the start of the exception’s message to provide some context.