ClickHouse/base/common/ErrorHandlers.h

38 lines
1015 B
C++
Raw Normal View History

#pragma once
#include <Poco/ErrorHandler.h>
#include <common/logger_useful.h>
#include <Common/Exception.h>
2017-12-02 02:47:12 +00:00
/** ErrorHandler for Poco::Thread,
* that in case of unhandled exception,
* logs exception message and terminates the process.
*/
class KillingErrorHandler : public Poco::ErrorHandler
{
public:
void exception(const Poco::Exception &) override { std::terminate(); }
void exception(const std::exception &) override { std::terminate(); }
void exception() override { std::terminate(); }
};
2017-12-02 02:47:12 +00:00
/** Log exception message.
*/
class ServerErrorHandler : public Poco::ErrorHandler
{
public:
void exception(const Poco::Exception &) override { logException(); }
void exception(const std::exception &) override { logException(); }
void exception() override { logException(); }
private:
2020-05-30 21:57:37 +00:00
Poco::Logger * log = &Poco::Logger::get("ServerErrorHandler");
void logException()
{
DB::tryLogCurrentException(log);
}
};