2015-09-29 19:21:02 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Poco/ErrorHandler.h>
|
|
|
|
#include <common/logger_useful.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Common/Exception.h>
|
2015-09-29 19:21:02 +00:00
|
|
|
|
|
|
|
|
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.
|
2015-09-29 19:21:02 +00:00
|
|
|
*/
|
|
|
|
class KillingErrorHandler : public Poco::ErrorHandler
|
|
|
|
{
|
|
|
|
public:
|
2020-01-21 08:54:26 +00:00
|
|
|
void exception(const Poco::Exception &) override { std::terminate(); }
|
|
|
|
void exception(const std::exception &) override { std::terminate(); }
|
|
|
|
void exception() override { std::terminate(); }
|
2015-09-29 19:21:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-12-02 02:47:12 +00:00
|
|
|
/** Log exception message.
|
2015-09-29 19:21:02 +00:00
|
|
|
*/
|
2016-01-14 03:17:11 +00:00
|
|
|
class ServerErrorHandler : public Poco::ErrorHandler
|
2015-09-29 19:21:02 +00:00
|
|
|
{
|
|
|
|
public:
|
2020-01-21 08:54:26 +00:00
|
|
|
void exception(const Poco::Exception &) override { logException(); }
|
|
|
|
void exception(const std::exception &) override { logException(); }
|
|
|
|
void exception() override { logException(); }
|
2015-09-29 19:21:02 +00:00
|
|
|
|
|
|
|
private:
|
2020-05-30 21:57:37 +00:00
|
|
|
Poco::Logger * log = &Poco::Logger::get("ServerErrorHandler");
|
2016-01-14 03:17:11 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
void logException()
|
|
|
|
{
|
|
|
|
DB::tryLogCurrentException(log);
|
|
|
|
}
|
2015-09-29 19:21:02 +00:00
|
|
|
};
|