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
handling_errors_and_warnings.cpp

This example presents how to catch exceptions to handle critical errors and how to use transformer to process non-critical errors (warnings) flowing through the pipeline

#include "docwire.h"
#include <cassert>
#include <sstream>
int main(int argc, char* argv[])
{
using namespace docwire;
std::stringstream out_stream;
try
{
std::filesystem::path("data_processing_definition.doc") |
content_type::by_file_extension::detector{} |
office_formats_parser{} |
PlainTextExporter() |
[](Tag&& tag, const emission_callbacks& emit_tag)
{
if (std::holds_alternative<std::exception_ptr>(tag))
{
std::clog << "[WARNING] " <<
errors::diagnostic_message(std::get<std::exception_ptr>(tag)) <<
std::endl;
}
return emit_tag(std::move(tag));
} |
out_stream;
}
catch (const std::exception& e)
{
std::cerr << "[ERROR] " << errors::diagnostic_message(e) << std::endl;
return 1;
}
return 0;
}
std::string diagnostic_message(const std::exception &e)
Generates a diagnostic message for the given nested exceptions chain.