Exceptions

The libc2pa library throws mostly common::runtime_error_with_context_impl exceptions when used incorrectly or when something goes wrong. This exception implements the common::runtime_error_with_context interface and is derived from std::runtime_error, which in turn is derived from std::exception.

Interface Features

The runtime_error_with_context interface has several methods that allow for a rich debugging experience when an error occurs.

message()

This returns a std::string with a simple message indicating the root of the problem that caused the exception.

openssl_error()

Since libc2pa relies very heavily on calls to the openssl library, many of the failures that can happen have their root in openssl code. In this case, this method will return the error message provided by the openssl library as a std::string.

context()

Many of the places that throw exceptions in libc2pa provide extra context about the state of the program. This context is provided in the form of a JSON object serialized into a std::string.

backtrace()

This isn't supported on all platforms, but on the platforms where it is supported, this will return a std::vector<std::string> array of lines indicating where in the code the exception occurred.

manifest_parser_info()

If the error occurred while parsing a C2PA Manifest, then this field will be populated with a serialized JSON object describing the state of the manifest parser at the time that the error occurred. This returns an instance of std::string.

Convert to a JSON Structure

The utility function JSONErrorFormatter::FormatError() can convert a runtime_error_with_context to a std::string containing a serialized JSON structure. See libc2pa Utility Functions for more info.