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
19namespace Poco {
20
21
22ErrorHandler* ErrorHandler::_pHandler = ErrorHandler::defaultHandler();
23FastMutex ErrorHandler::_mutex;
24
25
26ErrorHandler::ErrorHandler()
27{
28}
29
30
31ErrorHandler::~ErrorHandler()
32{
33}
34
35
36void ErrorHandler::exception(const Exception& exc)
37{
38 poco_debugger_msg(exc.what());
39}
40
41
42void ErrorHandler::exception(const std::exception& exc)
43{
44 poco_debugger_msg(exc.what());
45}
46
47
48void ErrorHandler::exception()
49{
50 poco_debugger_msg("unknown exception");
51}
52
53
54void 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
67void 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
80void ErrorHandler::handle()
81{
82 FastMutex::ScopedLock lock(_mutex);
83 try
84 {
85 _pHandler->exception();
86 }
87 catch (...)
88 {
89 }
90}
91
92
93ErrorHandler* 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
104ErrorHandler* 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