25 # ifndef CRN_PF_ANDROID
26 # include <execinfo.h>
33 # if !defined(CRN_PF_ANDROID) && !defined(_MSC_VER)
40 static const std::string getCallStack()
47 # ifdef CRN_PF_ANDROID
50 const size_t maxdepth = 20;
51 void *array[maxdepth];
52 size_t size = backtrace(array, maxdepth);
53 char **strings = backtrace_symbols(array,
int(size));
56 for (
size_t tmp = 1; tmp < size; ++tmp)
58 std::string line(strings[tmp]);
59 char *begin =
nullptr, *end =
nullptr;
60 for (
char *j = strings[tmp]; *j !=
'\0'; ++j)
77 char *ret = abi::__cxa_demangle(begin,
nullptr,
nullptr, &status);
80 const char *excstring =
"crn::Exception";
81 if (strncmp(ret, excstring, strlen(excstring)) != 0)
109 static bool trace =
false;
115 context(getCallStack())
124 context(getCallStack())
133 context(getCallStack())
167 return message.c_str();
170 static void crnterminate()
178 const char *exname =
typeid(ex).name();
181 char *ret = abi::__cxa_demangle(exname,
nullptr,
nullptr, &status);
187 std::cerr <<
"Unhandled <" << exname <<
">: " << std::endl;
191 std::cerr <<
"what: " << ex.
what() << std::endl;
192 std::cerr <<
"context: " << ex.
GetContext().c_str() << std::endl;
194 catch (
const std::exception &ex)
196 const char *exname =
typeid(ex).name();
199 char *ret = abi::__cxa_demangle(exname,
nullptr,
nullptr, &status);
205 std::cerr <<
"Unhandled <" << exname <<
">: " << std::endl;
209 std::cerr <<
"what: " << ex.what() << std::endl;
213 std::cerr <<
"Unexpected exception!" << std::endl;
221 std::set_terminate(crnterminate);
ExceptionRuntime() noexcept
Default constructor.
virtual ~Exception() noexceptoverride
Destructor.
const std::string & GetMessage() const noexcept
String containing a description of the exception.
ExceptionInvalidArgument() noexcept
Default constructor.
ExceptionDimension() noexcept
Default constructor.
ExceptionIO() noexcept
Default constructor.
const std::string & GetContext() const noexcept
String containing the call stack at the moment of throw.
static bool & TraceStack()
Shall the stack be traced at each exception thrown? (very slow)
ExceptionUninitialized() noexcept
Default constructor.
static void SetDefaultHandler()
Sets the default exception handler to print message and context to the standard error.
Exception() noexcept
Default constructor.
virtual const char * what() const noexceptoverride
String containing a description of the exception.
ExceptionTODO() noexcept
Default constructor.
A character string class.
ExceptionNotFound() noexcept
Default constructor.
Base class for exceptions.
ExceptionLogic() noexcept
Default constructor.
ExceptionDomain() noexcept
Default constructor.
ExceptionProtocol() noexcept
Default constructor.