Next: , Previous: Utilities, Up: Top

8 Error Handling

Most functions in `KSBA' will return an error if they fail. For this reason, the application should always catch the error condition and take appropriate measures, for example by releasing the resources and passing the error up to the caller, or by displaying a descriptive message to the user and canceling the operation.

Some error values do not indicate a system error or an error in the operation, but the reasonable result of an operation. For example, if you try to access optional attributes of a certificate that are not present, you get an appropriate error message. Some error values have specific meanings if returned by a specific function. Such cases are described in the documentation of those functions.

All error codes are defined by the library libgpg-error. See there for ways to check the error values and print descriptive strings. Please be aware that you can't check directly against an error code but have to do it like this:

       err = ksba_foo ();
       if (gpg_err_code (err) == GPG_ERR_EOF)
         okay = 1;

The only exception is that success (i.e. no error) is defined to be 0; thus you may directly test for success like:

       if (!ksba_foo ())
         okay = 1;