.. _error_handling:

==============
Error handling
==============

When an error occurs within the SDK, a :ref:`DocumentException<id3_document_document_exception>` exception is thrown. Generally you should wrap all invocations of the API into a try-catch block. 

.. tab-set::

    .. tab-item:: Python
      :sync: Python

      .. code:: Python

        try:
            # ...
        except DocumentException as ex:
            print(f"Document SDK exception: {ex}")

    .. tab-item:: Dart
      :sync: Dart

      .. code:: dart

        try
        {
           // ...
        }
        on DocumentException catch (e) {
            print('Document SDK exception: $e');
        }

    .. tab-item:: C#
      :sync: C#

      .. code:: C#

        try
        {
           // ...
        }
        catch (DocumentException ex)
        {
            Console.WriteLine(ex.Message);
        }

    .. tab-item:: Java
      :sync: Java

      .. code:: Java

        try {
            // ...
        }
        catch (DocumentException ex) {
        }

    .. tab-item:: Swift
      :sync: Swift

      .. code:: Swift

        do {
            // ...
        } catch let error as DocumentException {
            print(error.message)
        }

    .. tab-item:: C
      :sync: C

      In C and C++ languages, you have to handle the errors manually. The possible error codes are listed in the :ref:`DocumentError<id3_document_document_error_enum>`, :ref:`ImageError<id3_document_image_error_enum>` and :ref:`LicenseError<id3_document_license_error_enum>` enumerations.

      An example is given below:
      
      .. code-block:: cpp

        int err = id3DocumentLibrary_CheckLicense(path, nullptr);
        if (err != id3DocumentError_Success) {
          // handle error here.
        }


See also
--------
- :ref:`id3_document_document_exception`
- :ref:`id3_document_document_error_enum`
- :ref:`id3_document_image_error_enum`
- :ref:`id3_document_license_error_enum`