ErrorHandler.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. //
  2. // ErrorHandler.h
  3. //
  4. // $Id: //poco/1.4/Foundation/include/Poco/ErrorHandler.h#1 $
  5. //
  6. // Library: Foundation
  7. // Package: Threading
  8. // Module: ErrorHandler
  9. //
  10. // Definition of the ErrorHandler class.
  11. //
  12. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
  13. // and Contributors.
  14. //
  15. // SPDX-License-Identifier: BSL-1.0
  16. //
  17. #ifndef Foundation_ErrorHandler_INCLUDED
  18. #define Foundation_ErrorHandler_INCLUDED
  19. #include "Poco/Foundation.h"
  20. #include "Poco/Exception.h"
  21. #include "Poco/Mutex.h"
  22. namespace Poco {
  23. class Foundation_API ErrorHandler
  24. /// This is the base class for thread error handlers.
  25. ///
  26. /// An unhandled exception that causes a thread to terminate is usually
  27. /// silently ignored, since the class library cannot do anything meaningful
  28. /// about it.
  29. ///
  30. /// The Thread class provides the possibility to register a
  31. /// global ErrorHandler that is invoked whenever a thread has
  32. /// been terminated by an unhandled exception.
  33. /// The ErrorHandler must be derived from this class and can
  34. /// provide implementations of all three exception() overloads.
  35. ///
  36. /// The ErrorHandler is always invoked within the context of
  37. /// the offending thread.
  38. {
  39. public:
  40. ErrorHandler();
  41. /// Creates the ErrorHandler.
  42. virtual ~ErrorHandler();
  43. /// Destroys the ErrorHandler.
  44. virtual void exception(const Exception& exc);
  45. /// Called when a Poco::Exception (or a subclass)
  46. /// caused the thread to terminate.
  47. ///
  48. /// This method should not throw any exception - it would
  49. /// be silently ignored.
  50. ///
  51. /// The default implementation just breaks into the debugger.
  52. virtual void exception(const std::exception& exc);
  53. /// Called when a std::exception (or a subclass)
  54. /// caused the thread to terminate.
  55. ///
  56. /// This method should not throw any exception - it would
  57. /// be silently ignored.
  58. ///
  59. /// The default implementation just breaks into the debugger.
  60. virtual void exception();
  61. /// Called when an exception that is neither a
  62. /// Poco::Exception nor a std::exception caused
  63. /// the thread to terminate.
  64. ///
  65. /// This method should not throw any exception - it would
  66. /// be silently ignored.
  67. ///
  68. /// The default implementation just breaks into the debugger.
  69. static void handle(const Exception& exc);
  70. /// Invokes the currently registered ErrorHandler.
  71. static void handle(const std::exception& exc);
  72. /// Invokes the currently registered ErrorHandler.
  73. static void handle();
  74. /// Invokes the currently registered ErrorHandler.
  75. static ErrorHandler* set(ErrorHandler* pHandler);
  76. /// Registers the given handler as the current error handler.
  77. ///
  78. /// Returns the previously registered handler.
  79. static ErrorHandler* get();
  80. /// Returns a pointer to the currently registered
  81. /// ErrorHandler.
  82. protected:
  83. static ErrorHandler* defaultHandler();
  84. /// Returns the default ErrorHandler.
  85. private:
  86. static ErrorHandler* _pHandler;
  87. static FastMutex _mutex;
  88. };
  89. //
  90. // inlines
  91. //
  92. inline ErrorHandler* ErrorHandler::get()
  93. {
  94. return _pHandler;
  95. }
  96. } // namespace Poco
  97. #endif // Foundation_ErrorHandler_INCLUDED