MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ error_rethrow() [2/2]

void MayaFlux::Journal::error_rethrow ( Component  component,
Context  context,
std::source_location  location = std::source_location::current(),
std::string_view  additional_context = "" 
)
inline

Catch and log an exception, then rethrow it.

This function is intended to be called within a catch block.

Parameters
ComponentThe component generating the log message.
ContextThe execution context of the log message.
locationThe source location (file, line, function) of the log call.
additional_contextOptional additional context to prepend to the exception message.

Definition at line 377 of file Archivist.hpp.

380{
381 auto ep = std::current_exception();
382 if (!ep) {
383 Archivist::instance().scribe(Severity::ERROR, component, context,
384 "error_rethrow called outside of a catch", location);
385 Archivist::instance().flush();
386 std::terminate();
387 }
388
389 try {
390 std::rethrow_exception(ep);
391 } catch (const std::exception& e) {
392 std::string msg = std::string(e.what());
393 if (!additional_context.empty()) {
394 msg = std::string(additional_context) + ": " + msg;
395 }
396 Archivist::instance().scribe(Severity::ERROR, component, context, msg, location);
397 Archivist::instance().flush();
398 std::rethrow_exception(ep);
399 } catch (...) {
400 std::string msg = "Unknown exception";
401 if (!additional_context.empty()) {
402 msg = std::string(additional_context) + ": " + msg;
403 }
404 Archivist::instance().scribe(Severity::ERROR, component, context, msg, location);
405 Archivist::instance().flush();
406 std::rethrow_exception(ep);
407 }
408}

References ERROR, MayaFlux::Journal::Archivist::flush(), MayaFlux::Journal::Archivist::instance(), and MayaFlux::Journal::Archivist::scribe().

Referenced by error_rethrow().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: