ClickHouse/dbms/src/Core/Exception.cpp

98 lines
1.8 KiB
C++
Raw Normal View History

2012-05-14 20:37:10 +00:00
#include <errno.h>
#include <string.h>
2013-11-18 19:18:03 +00:00
#include <Yandex/logger_useful.h>
2013-06-21 20:34:19 +00:00
#include <DB/IO/WriteHelpers.h>
2012-05-14 20:37:10 +00:00
2010-03-01 16:59:51 +00:00
#include <DB/Core/Exception.h>
namespace DB
{
2011-12-12 06:15:34 +00:00
void throwFromErrno(const std::string & s, int code, int e)
2012-05-14 20:37:10 +00:00
{
char buf[128];
2013-06-21 20:34:19 +00:00
throw Exception(s + ", errno: " + toString(e) + ", strerror: " + std::string(strerror_r(e, buf, sizeof(buf))), code);
2012-05-14 20:37:10 +00:00
}
ExceptionPtr cloneCurrentException()
{
try
{
throw;
}
catch (const Exception & e)
{
return e.clone();
}
catch (const Poco::Exception & e)
{
return e.clone();
}
catch (const std::exception & e)
{
return new Exception(e.what(), ErrorCodes::STD_EXCEPTION);
}
catch (...)
{
return new Exception("Unknown exception", ErrorCodes::UNKNOWN_EXCEPTION);
}
}
2013-11-18 19:18:03 +00:00
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)
if (exceptions[i])
exceptions[i]->rethrow();
}
2010-03-01 16:59:51 +00:00
}