.. _error_handling:

===============
Error Handling
===============

When an error occurs within the SDK, a :ref:`FaceException<id3_face_face_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 id3face.FaceException as ex:
            print(f"SDK exception: {ex}")

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

      .. code:: dart

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

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

      .. code:: C#

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

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

      .. code:: Java

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

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

      .. code:: Swift

        do {
            // ...
        } catch let error as FaceException {
            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:`FaceError<id3_face_face_error_enum>`, :ref:`ImageError<id3_face_image_error_enum>` and :ref:`LicenseError<id3_face_license_error_enum>` enumerations.

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

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


See also
--------
- :ref:`id3_face_face_exception`
- :ref:`id3_face_face_error_enum`
- :ref:`id3_face_image_error_enum`
- :ref:`id3_face_license_error_enum`