| 1 | #pragma once | 
|---|---|
| 2 | |
| 3 | #include <Poco/ErrorHandler.h> | 
| 4 | #include <common/logger_useful.h> | 
| 5 | #include <Common/Exception.h> | 
| 6 | |
| 7 | |
| 8 | /** ErrorHandler for Poco::Thread, | 
| 9 | * that in case of unhandled exception, | 
| 10 | * logs exception message and terminates the process. | 
| 11 | */ | 
| 12 | class KillingErrorHandler : public Poco::ErrorHandler | 
| 13 | { | 
| 14 | public: | 
| 15 | void exception(const Poco::Exception &) { std::terminate(); } | 
| 16 | void exception(const std::exception &) { std::terminate(); } | 
| 17 | void exception() { std::terminate(); } | 
| 18 | }; | 
| 19 | |
| 20 | |
| 21 | /** Log exception message. | 
| 22 | */ | 
| 23 | class ServerErrorHandler : public Poco::ErrorHandler | 
| 24 | { | 
| 25 | public: | 
| 26 | void exception(const Poco::Exception &) { logException(); } | 
| 27 | void exception(const std::exception &) { logException(); } | 
| 28 | void exception() { logException(); } | 
| 29 | |
| 30 | private: | 
| 31 | Logger * log = &Logger::get( "ServerErrorHandler"); | 
| 32 | |
| 33 | void logException() | 
| 34 | { | 
| 35 | DB::tryLogCurrentException(log); | 
| 36 | } | 
| 37 | }; | 
| 38 | 
