ErrorHandler.cpp 1.7 KB

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