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
#define DOCWIRE_ENABLE_SHORT_MACRO_NAMES
#include "docwire.h"
#include "error_tags.h"
#include "error.h"
#include "make_error.h"
#include "contains_type.h"
#include <filesystem>
#include <iostream>
#include <sstream>
void retry()
{
}
void demonstrate_error_handling()
{
try
{
}
{
retry();
}
try
{
throw make_error("Demonstration error");
}
{
}
try
{
throw make_error(std::filesystem::path{"/secret/file.txt"});
}
{
{
auto fn = impl_ptr->context;
(void)fn;
}
}
}
int main(int argc, char* argv[])
{
std::stringstream out_stream;
try
{
std::filesystem::path("data_processing_definition.doc") |
{
if (msg->is<std::exception_ptr>())
{
std::clog << "[WARNING] " <<
std::endl;
}
return emit_message(std::move(msg));
} |
out_stream;
}
catch (const std::exception& e)
{
return 1;
}
demonstrate_error_handling();
return 0;
}
Exports data to plain text format.
std::string diagnostic_message(const std::exception &e)
Generates a diagnostic message for the given nested exceptions chain.
bool contains_type(const std::exception &e)
Checks if the given nested exceptions chain contains a specific type of context.
The main namespace for the DocWire SDK.
Base class for all exceptions in the SDK.
source_location location
The source location where the exception was thrown.
Implementation of the error class for a variadic number of context items.
Network failure error tag.
Callback bundle used by pipeline elements to emit messages.