dbms: better [#METR-9194].

This commit is contained in:
Alexey Milovidov 2013-11-18 19:18:03 +00:00
parent 4ef53f6acb
commit 025531e1c5
11 changed files with 59 additions and 0 deletions

View File

@ -51,6 +51,11 @@ void throwFromErrno(const std::string & s, int code = 0, int the_errno = errno);
*/
ExceptionPtr cloneCurrentException();
/** Попробовать записать исключение в лог (и забыть про него).
* Можно использовать в деструкторах в блоке catch (...).
*/
void tryLogCurrentException(const char * log_name);
void rethrowFirstException(Exceptions & exceptions);

View File

@ -73,6 +73,7 @@ public:
}
catch (...)
{
tryLogCurrentException(__PRETTY_FUNCTION__);
}
}

View File

@ -126,6 +126,7 @@ public:
}
catch (...)
{
tryLogCurrentException(__PRETTY_FUNCTION__);
}
delete qlz_state;

View File

@ -43,6 +43,7 @@ public:
}
catch (...)
{
tryLogCurrentException(__PRETTY_FUNCTION__);
}
}
};

View File

@ -162,6 +162,7 @@ public:
}
catch (...)
{
tryLogCurrentException(__PRETTY_FUNCTION__);
}
}

View File

@ -35,6 +35,7 @@ public:
}
catch (...)
{
tryLogCurrentException(__PRETTY_FUNCTION__);
}
close(fd);

View File

@ -65,6 +65,7 @@ public:
}
catch (...)
{
tryLogCurrentException(__PRETTY_FUNCTION__);
}
}

View File

@ -56,6 +56,7 @@ public:
}
catch (...)
{
tryLogCurrentException(__PRETTY_FUNCTION__);
}
}
};

View File

@ -41,6 +41,7 @@ public:
}
catch (...)
{
tryLogCurrentException(__PRETTY_FUNCTION__);
}
}
};

View File

@ -62,6 +62,7 @@ public:
}
catch (...)
{
tryLogCurrentException(__PRETTY_FUNCTION__);
}
}
};

View File

@ -1,6 +1,8 @@
#include <errno.h>
#include <string.h>
#include <Yandex/logger_useful.h>
#include <DB/IO/WriteHelpers.h>
#include <DB/Core/Exception.h>
@ -82,6 +84,49 @@ ExceptionPtr cloneCurrentException()
}
void tryLogCurrentException(const char * log_name)
{
try
{
throw;
}
catch (const Exception & e)
{
try
{
LOG_ERROR(&Logger::get(log_name), "Code: " << e.code() << ", e.displayText() = " << e.displayText() << ", e.what() = " << e.what()
<< ", Stack trace:\n\n" << e.getStackTrace().toString());
}
catch (...) {}
}
catch (const Poco::Exception & e)
{
try
{
LOG_ERROR(&Logger::get(log_name), "Poco::Exception. Code: " << ErrorCodes::POCO_EXCEPTION << ", e.code() = " << e.code()
<< ", e.displayText() = " << e.displayText() << ", e.what() = " << e.what());
}
catch (...) {}
}
catch (const std::exception & e)
{
try
{
LOG_ERROR(&Logger::get(log_name), "std::exception. Code: " << ErrorCodes::STD_EXCEPTION << ", e.what() = " << e.what());
}
catch (...) {}
}
catch (...)
{
try
{
LOG_ERROR(&Logger::get(log_name), "Unknown exception. Code: " << ErrorCodes::UNKNOWN_EXCEPTION);
}
catch (...) {}
}
}
void rethrowFirstException(Exceptions & exceptions)
{
for (size_t i = 0, size = exceptions.size(); i < size; ++i)