std::string getExceptionMessage(const Exception & e, bool with_stacktrace, bool check_embedded_stacktrace) { std::stringstream stream; try { std::string text = e.displayText(); bool has_embedded_stack_trace = false; if (check_embedded_stacktrace) { auto embedded_stack_trace_pos = text.find("Stack trace"); has_embedded_stack_trace = embedded_stack_trace_pos != std::string::npos; if (!with_stacktrace && has_embedded_stack_trace) { text.resize(embedded_stack_trace_pos); Poco::trimRightInPlace(text); } } stream << "Code: " << e.code() << ", e.displayText() = " << text; if (with_stacktrace && !has_embedded_stack_trace) stream << ", Stack trace:\n\n" << e.getStackTrace().toString(); } catch (...) {} return stream.str(); }
void kdrive::connector::raiseError(Connector& connector, const Exception& exception) { const int errorCode = exception.code() ? exception.code() : ConnectorErrorCodes::ConnectorError; connector.setLastErrorCode(errorCode); connector.setLastErrorMessage(exception.displayText()); connector.routeEvent(ConnectorEvents::Error); exception.rethrow(); }
void writeException(const Exception & e, WriteBuffer & buf, bool with_stack_trace) { writeBinary(e.code(), buf); writeBinary(String(e.name()), buf); writeBinary(e.displayText(), buf); if (with_stack_trace) writeBinary(e.getStackTrace().toString(), buf); else writeBinary(String(), buf); bool has_nested = e.nested() != nullptr; writeBinary(has_nested, buf); if (has_nested) writeException(Exception(Exception::CreateFromPoco, *e.nested()), buf, with_stack_trace); }
void Logger::log(const Exception& exc, const char* file, int line) { error(exc.displayText(), file, line); }
void Logger::log(const Exception& exc) { error(exc.displayText()); }