DocWire SDK
DocWire SDK: Award-winning modern data processing in C++20. SourceForge Community Choice & Microsoft support. AI-driven processing. Supports nearly 100 data formats, including email boxes and OCR. Boost efficiency in text extraction, web data extraction, data mining, document analysis. Offline processing possible for security and confidentiality
docwire::errors::base Struct Referenceabstract

Base class for all exceptions in the SDK. More...

#include <error.h>

Inheritance diagram for docwire::errors::base:
docwire::errors::impl< T >

Public Member Functions

 base (const source_location &location=source_location::current())
 Constructs a base object with the current source location. More...
 
virtual std::type_info const & context_type (size_t index) const noexcept=0
 Get the type information of the context. More...
 
virtual std::string context_string (size_t index) const =0
 Get the string representation of the context. More...
 
virtual size_t context_count () const noexcept=0
 Get the number of context items.
 
virtual const char * what () const noexcept override
 Get the exception type. More...
 

Public Attributes

source_location location
 The source location where the exception was thrown.
 

Detailed Description

Base class for all exceptions in the SDK.

This class provides a foundation for exceptions in the SDK, combining the ability to throw any object as an exception with compatibility with the standard C++ exception class, std::exception.

The class is designed to hold context information of any type, such as error messages, error tags, or important context values. This information can be stored in the form of a string, a name-value pair, or any other C++ type.

In addition to the context information, this class also stores the source location where the exception was thrown. This information is useful for debugging and error reporting purposes.

Note
This class is intended to be used as a base class for other exception classes in the SDK. It should not be used directly for throwing exceptions. Instead, use the errors::impl template or the make_error macro to create derived exception classes.
The what() method returns the exception type instead of a formatted message. This is because pre-formatting error messages in exceptions can have significant drawbacks, including the potential for confidential data to be leaked without the application's control. To avoid this, use the errors::diagnostic_message function instead.
try {
// SDK code that may throw an error
} catch (const docwire::errors::base& e) {
std::cerr << "Exception type: " << e.what() << std::endl;
// Manually inspect context items:
for (size_t i = 0; i < e.context_count(); ++i) {
std::cerr << " Context item " << i << ": " << e.context_string(i) << std::endl;
}
// Or print the full, user-friendly diagnostic message:
std::cerr << errors::diagnostic_message(e) << std::endl;
}
DOCWIRE_CORE_EXPORT std::string diagnostic_message(const std::exception &e)
Generates a diagnostic message for the given nested exceptions chain.
Base class for all exceptions in the SDK.
Definition: error.h:75
virtual std::string context_string(size_t index) const =0
Get the string representation of the context.
virtual size_t context_count() const noexcept=0
Get the number of context items.
virtual const char * what() const noexcept override
Get the exception type.
See also
errors::impl
errors::make_error
errors::diagnostic_message
handling errors and warnings example

Definition at line 74 of file error.h.

Constructor & Destructor Documentation

◆ base()

docwire::errors::base::base ( const source_location location = source_location::current())

Constructs a base object with the current source location.

Parameters
locationThe source location of the exception (initialized by current location by default).

Member Function Documentation

◆ context_string()

virtual std::string docwire::errors::base::context_string ( size_t  index) const
pure virtual

Get the string representation of the context.

Parameters
indexThe index of the context item.
Returns
The string representation of the context item at the given index.
See also
context_type

Implemented in docwire::errors::impl< T >.

◆ context_type()

virtual std::type_info const& docwire::errors::base::context_type ( size_t  index) const
pure virtualnoexcept

Get the type information of the context.

Parameters
indexThe index of the context item.
Returns
The type information of the context item at the given index.
See also
context_string

Implemented in docwire::errors::impl< T >.

◆ what()

virtual const char* docwire::errors::base::what ( ) const
overridevirtualnoexcept

Get the exception type.

This method is provided for compatibility with the standard C++ exception class. It returns the type name of the exception instead of a formatted message for security reasons.

Returns
The exception type.
See also
diagnostic_message

The documentation for this struct was generated from the following file: