Specs
Beautiful C++ Test Framework
Loading...
Searching...
No Matches
LibAssertExceptionHandler.h File Reference
#include <assert.hpp>

Go to the source code of this file.

Namespaces

namespace  SpecsCpp
 
namespace  SpecsCpp::LibAssert
 

Functions

void libassert_specs_handler (libassert::assert_type type, ASSERTION fatal, const libassert::assertion_printer &printer)
 

Variables

bool SpecsCpp::LibAssert::ShowStackTrace = false
 

Function Documentation

◆ libassert_specs_handler()

void libassert_specs_handler ( libassert::assert_type  type,
ASSERTION  fatal,
const libassert::assertion_printer &  printer 
)
inline

Definition at line 20 of file LibAssertExceptionHandler.h.

22 {
23 std::string message = printer(libassert::utility::terminal_width(120));
25 std::string::size_type stack_trace_start = message.find("\nStack trace:");
26 if (stack_trace_start != std::string::npos) message.erase(stack_trace_start);
27 }
28 #ifdef NDEBUG
29 // In release mode, the c_str() is lost unless we hold onto the string somewhere.
30 // Here we just add it to a never-ending vector. Which is fine, whatever.
31 std::lock_guard<std::mutex> lock(SpecsCpp::LibAssert::AllAssertionFailureMessagesMutex);
32 SpecsCpp::LibAssert::AllAssertionFailureMessages.emplace_back(message);
33 throw SpecsCpp::LibAssert::AllAssertionFailureMessages.back().c_str();
34 #else
35 throw message.c_str();
36 #endif
37}