File: error.rst

package info (click to toggle)
python-av 16.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,684 kB
  • sloc: python: 7,607; sh: 182; ansic: 174; makefile: 135
file content (55 lines) | stat: -rw-r--r-- 1,694 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
Errors
======

.. currentmodule:: av.error

.. _error_behaviour:

General Behavior
-----------------

When PyAV encounters an FFmpeg error, it raises an appropriate exception.

FFmpeg has a couple dozen of its own error types which we represent via
:ref:`error_classes`.

FFmpeg will also return more typical errors such as ``ENOENT`` or ``EAGAIN``,
which we do our best to translate to extensions of the builtin exceptions
as defined by
`PEP 3151 <https://www.python.org/dev/peps/pep-3151/#new-exception-classes>`_.


.. _error_classes:

Error Exception Classes
-----------------------

PyAV raises the typical builtin exceptions within its own codebase, but things
get a little more complex when it comes to translating FFmpeg errors.

There are two competing ideas that have influenced the final design:

1. We want every exception that originates within FFmpeg to inherit from a common
   :class:`.FFmpegError` exception;

2. We want to use the builtin exceptions whenever possible.

As such, PyAV effectively shadows as much of the builtin exception hierarchy as
it requires, extending from both the builtins and from :class:`FFmpegError`.

Therefore, an argument error within FFmpeg will raise a ``av.error.ValueError``, which
can be caught via either :class:`FFmpegError` or ``ValueError``. All of these
exceptions expose the typical ``errno`` and ``strerror`` attributes (even
``ValueError`` which doesn't typically), as well as some PyAV extensions such
as :attr:`FFmpegError.log`.

All of these exceptions are available on the top-level ``av`` package, e.g.::

    try:
        do_something()
    except av.FilterNotFoundError:
        handle_error()


.. autoclass:: av.FFmpegError