DocWire SDK
DocWire SDK: Deterministic, auditable, and secure data processing in C++20. On-premise by default. No compromises on computational speed.
Loading...
Searching...
No Matches
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.
 base (const base &)
 base (base &&)
base & operator= (const base &)
base & operator= (base &&)
virtual type_id context_type_id (size_t index) const noexcept=0
 Get the type information of the context.
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.
const char * what () const noexcept override
 Get the exception type.

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;
}
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:76
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.
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
Examples
handling_errors_and_warnings.cpp.

Definition at line 75 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_count()

virtual size_t docwire::errors::base::context_count ( ) const
pure virtualnoexcept

Get the number of context items.

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

◆ 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_id()

virtual type_id docwire::errors::base::context_type_id ( 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()

const char * docwire::errors::base::what ( ) const
overridenoexcept

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

Member Data Documentation

◆ location

source_location docwire::errors::base::location

The source location where the exception was thrown.

Examples
handling_errors_and_warnings.cpp.

Definition at line 78 of file error.h.


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