| 1 | // | 
|---|---|
| 2 | // ErrorHandler.cpp | 
| 3 | // | 
| 4 | // Library: Foundation | 
| 5 | // Package: Threading | 
| 6 | // Module: ErrorHandler | 
| 7 | // | 
| 8 | // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. | 
| 9 | // and Contributors. | 
| 10 | // | 
| 11 | // SPDX-License-Identifier: BSL-1.0 | 
| 12 | // | 
| 13 | |
| 14 | |
| 15 | #include "Poco/ErrorHandler.h" | 
| 16 | #include "Poco/SingletonHolder.h" | 
| 17 | |
| 18 | |
| 19 | namespace Poco { | 
| 20 | |
| 21 | |
| 22 | ErrorHandler* ErrorHandler::_pHandler = ErrorHandler::defaultHandler(); | 
| 23 | FastMutex ErrorHandler::_mutex; | 
| 24 | |
| 25 | |
| 26 | ErrorHandler::ErrorHandler() | 
| 27 | { | 
| 28 | } | 
| 29 | |
| 30 | |
| 31 | ErrorHandler::~ErrorHandler() | 
| 32 | { | 
| 33 | } | 
| 34 | |
| 35 | |
| 36 | void ErrorHandler::exception(const Exception& exc) | 
| 37 | { | 
| 38 | poco_debugger_msg(exc.what()); | 
| 39 | } | 
| 40 | |
| 41 | |
| 42 | void ErrorHandler::exception(const std::exception& exc) | 
| 43 | { | 
| 44 | poco_debugger_msg(exc.what()); | 
| 45 | } | 
| 46 | |
| 47 | |
| 48 | void ErrorHandler::exception() | 
| 49 | { | 
| 50 | poco_debugger_msg( "unknown exception"); | 
| 51 | } | 
| 52 | |
| 53 | |
| 54 | void ErrorHandler::handle(const Exception& exc) | 
| 55 | { | 
| 56 | FastMutex::ScopedLock lock(_mutex); | 
| 57 | try | 
| 58 | { | 
| 59 | _pHandler->exception(exc); | 
| 60 | } | 
| 61 | catch (...) | 
| 62 | { | 
| 63 | } | 
| 64 | } | 
| 65 | |
| 66 | |
| 67 | void ErrorHandler::handle(const std::exception& exc) | 
| 68 | { | 
| 69 | FastMutex::ScopedLock lock(_mutex); | 
| 70 | try | 
| 71 | { | 
| 72 | _pHandler->exception(exc); | 
| 73 | } | 
| 74 | catch (...) | 
| 75 | { | 
| 76 | } | 
| 77 | } | 
| 78 | |
| 79 | |
| 80 | void ErrorHandler::handle() | 
| 81 | { | 
| 82 | FastMutex::ScopedLock lock(_mutex); | 
| 83 | try | 
| 84 | { | 
| 85 | _pHandler->exception(); | 
| 86 | } | 
| 87 | catch (...) | 
| 88 | { | 
| 89 | } | 
| 90 | } | 
| 91 | |
| 92 | |
| 93 | ErrorHandler* ErrorHandler::set(ErrorHandler* pHandler) | 
| 94 | { | 
| 95 | poco_check_ptr(pHandler); | 
| 96 | |
| 97 | FastMutex::ScopedLock lock(_mutex); | 
| 98 | ErrorHandler* pOld = _pHandler; | 
| 99 | _pHandler = pHandler; | 
| 100 | return pOld; | 
| 101 | } | 
| 102 | |
| 103 | |
| 104 | ErrorHandler* ErrorHandler::defaultHandler() | 
| 105 | { | 
| 106 | // NOTE: Since this is called to initialize the static _pHandler | 
| 107 | // variable, sh has to be a local static, otherwise we run | 
| 108 | // into static initialization order issues. | 
| 109 | static SingletonHolder<ErrorHandler> sh; | 
| 110 | return sh.get(); | 
| 111 | } | 
| 112 | |
| 113 | |
| 114 | } // namespace Poco | 
| 115 | 
