Exceptions

Docraft provides a domain-based exception system under docraft::exception.

The exception model is designed to:

  • keep error types aligned with functional domains,

  • avoid direct use of std::runtime_error and similar standard exception types,

  • make API and test expectations explicit and stable.

Base Exception

All Docraft exceptions derive from DocraftException.

class DocraftException

Base exception class for the Docraft library.

All Docraft-specific exceptions inherit from this class. This class intentionally does not inherit from standard exception types.

Subclassed by docraft::exception::BackendStateException, docraft::exception::ConfigurationException, docraft::exception::DataFormatException, docraft::exception::DocumentException, docraft::exception::FileSystemException, docraft::exception::InvalidInputException, docraft::exception::LayoutException, docraft::exception::NotImplementedException, docraft::exception::RenderingException, docraft::exception::TemplateException

Public Functions

inline explicit DocraftException(const std::string &message)

Constructs a DocraftException with a message.

Parameters:

message – The error message.

inline const char *what() const noexcept

Returns the exception message as a C-string.

This method follows a classic what()-style API.

Returns:

A C-string containing the error message.

inline const std::string &message() const noexcept

Returns the message as a std::string.

Returns:

The error message.

DocraftException(const DocraftException &other) noexcept = default
DocraftException &operator=(const DocraftException &other) noexcept = default
DocraftException(DocraftException &&other) noexcept = default
DocraftException &operator=(DocraftException &&other) noexcept = default
virtual ~DocraftException() noexcept = default

Domain Overview

  • Configuration: invalid command-line/configuration state.

  • FileSystem: missing or unreadable files.

  • DataFormat: invalid JSON/XML/data structures.

  • Input: invalid values provided by caller or parsed attributes.

  • Template: template variables and template image data errors.

  • Layout: layout pipeline failures and configuration issues.

  • Document: document/model lifecycle and state errors.

  • Backend: backend capability/page/runtime state errors.

  • Rendering: rendering-specific failures.

  • Implementation: intentionally unimplemented features.

Domain Classes

Configuration

class ConfigurationException : public docraft::exception::DocraftException

Exception thrown for configuration-related errors.

Subclassed by docraft::exception::MissingArgumentException

Public Functions

inline explicit DocraftException(const std::string &message)

Constructs a DocraftException with a message.

Parameters:

message – The error message.

DocraftException(const DocraftException &other) noexcept = default
DocraftException(DocraftException &&other) noexcept = default
class MissingArgumentException : public docraft::exception::ConfigurationException

Exception thrown when a required argument is missing.

FileSystem

class FileSystemException : public docraft::exception::DocraftException

Base exception for file system-related errors.

Subclassed by docraft::exception::CannotOpenFileException, docraft::exception::FileNotFoundException

Public Functions

inline explicit DocraftException(const std::string &message)

Constructs a DocraftException with a message.

Parameters:

message – The error message.

DocraftException(const DocraftException &other) noexcept = default
DocraftException(DocraftException &&other) noexcept = default
class FileNotFoundException : public docraft::exception::FileSystemException

Exception thrown when a file cannot be found.

class CannotOpenFileException : public docraft::exception::FileSystemException

Exception thrown when a file cannot be opened.

DataFormat

class DataFormatException : public docraft::exception::DocraftException

Base exception for data format-related errors.

Subclassed by docraft::exception::InvalidJSONException

Public Functions

inline explicit DocraftException(const std::string &message)

Constructs a DocraftException with a message.

Parameters:

message – The error message.

DocraftException(const DocraftException &other) noexcept = default
DocraftException(DocraftException &&other) noexcept = default
class InvalidJSONException : public docraft::exception::DataFormatException

Exception thrown when JSON parsing fails.

Input

class InvalidInputException : public docraft::exception::DocraftException

Exception thrown for invalid input validation errors.

Public Functions

inline explicit DocraftException(const std::string &message)

Constructs a DocraftException with a message.

Parameters:

message – The error message.

DocraftException(const DocraftException &other) noexcept = default
DocraftException(DocraftException &&other) noexcept = default

Template

class TemplateException : public docraft::exception::DocraftException

Base exception for template-related errors.

Subclassed by docraft::exception::TemplateImageDataException, docraft::exception::TemplateVariableExistsException, docraft::exception::TemplateVariableNotFoundException

Public Functions

inline explicit DocraftException(const std::string &message)

Constructs a DocraftException with a message.

Parameters:

message – The error message.

DocraftException(const DocraftException &other) noexcept = default
DocraftException(DocraftException &&other) noexcept = default
class TemplateVariableExistsException : public docraft::exception::TemplateException

Exception thrown when a template variable already exists.

class TemplateVariableNotFoundException : public docraft::exception::TemplateException

Exception thrown when a template variable is not found.

class TemplateImageDataException : public docraft::exception::TemplateException

Exception thrown when template image data is invalid or missing.

Layout

class LayoutException : public docraft::exception::DocraftException

Base exception for layout-related errors.

Subclassed by docraft::exception::LayoutConfigurationException

Public Functions

inline explicit DocraftException(const std::string &message)

Constructs a DocraftException with a message.

Parameters:

message – The error message.

DocraftException(const DocraftException &other) noexcept = default
DocraftException(DocraftException &&other) noexcept = default
class LayoutConfigurationException : public docraft::exception::LayoutException

Exception thrown for layout configuration errors.

Document

class DocumentException : public docraft::exception::DocraftException

Base exception for document-related errors.

Subclassed by docraft::exception::DocumentStateException, docraft::exception::ModelException

Public Functions

inline explicit DocraftException(const std::string &message)

Constructs a DocraftException with a message.

Parameters:

message – The error message.

DocraftException(const DocraftException &other) noexcept = default
DocraftException(DocraftException &&other) noexcept = default
class DocumentStateException : public docraft::exception::DocumentException

Exception thrown when document state is invalid.

class ModelException : public docraft::exception::DocumentException

Exception thrown for model-related document errors.

Backend

class BackendStateException : public docraft::exception::DocraftException

Base exception for backend-related errors.

Subclassed by docraft::exception::CapabilityUnavailableException, docraft::exception::PageStateException

Public Functions

inline explicit DocraftException(const std::string &message)

Constructs a DocraftException with a message.

Parameters:

message – The error message.

DocraftException(const DocraftException &other) noexcept = default
DocraftException(DocraftException &&other) noexcept = default
class CapabilityUnavailableException : public docraft::exception::BackendStateException

Exception thrown when a required capability is unavailable.

class PageStateException : public docraft::exception::BackendStateException

Exception thrown for page state errors.

Rendering

class RenderingException : public docraft::exception::DocraftException

Base exception for rendering-related errors.

Subclassed by docraft::exception::RenderingFailedException

Public Functions

inline explicit DocraftException(const std::string &message)

Constructs a DocraftException with a message.

Parameters:

message – The error message.

DocraftException(const DocraftException &other) noexcept = default
DocraftException(DocraftException &&other) noexcept = default
class RenderingFailedException : public docraft::exception::RenderingException

Exception thrown when rendering fails.

Implementation

class NotImplementedException : public docraft::exception::DocraftException

Exception thrown when a feature is not yet implemented.

Public Functions

inline explicit DocraftException(const std::string &message)

Constructs a DocraftException with a message.

Parameters:

message – The error message.

DocraftException(const DocraftException &other) noexcept = default
DocraftException(DocraftException &&other) noexcept = default

Usage Example

#include "docraft/exception/docraft_exception.h"

void use_template(const docraft::templating::DocraftTemplateEngine& engine) {
    try {
        auto value = engine.find_template_variable("invoice_number");
        (void)value;
    } catch (const docraft::exception::TemplateVariableNotFoundException& ex) {
        // Handle only missing-variable errors
    } catch (const docraft::exception::DocraftException& ex) {
        // Fallback for all Docraft domain exceptions
    }
}

Headers

  • docraft/exception/docraft_exception.h: compatibility include for the full exception set.

  • docraft/exception/docraft_exceptions.h: master include for all exception domains.

  • docraft/exception/docraft_*_exceptions.h: domain-specific headers.