/src/poco/Foundation/src/Bugcheck.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | // |
2 | | // Bugcheck.cpp |
3 | | // |
4 | | // Library: Foundation |
5 | | // Package: Core |
6 | | // Module: Bugcheck |
7 | | // |
8 | | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. |
9 | | // and Contributors. |
10 | | // |
11 | | // SPDX-License-Identifier: BSL-1.0 |
12 | | // |
13 | | |
14 | | |
15 | | #include "Poco/Bugcheck.h" |
16 | | #include "Poco/Debugger.h" |
17 | | #include "Poco/Exception.h" |
18 | | #include <sstream> |
19 | | |
20 | | |
21 | | namespace Poco { |
22 | | |
23 | | |
24 | | void Bugcheck::assertion(const char* cond, const char* file, LineNumber line, const char* text) |
25 | 121k | { |
26 | 121k | std::string message("Assertion violation: "); |
27 | 121k | message += cond; |
28 | 121k | if (text) |
29 | 0 | { |
30 | 0 | message += " ("; |
31 | 0 | message += text; |
32 | 0 | message += ")"; |
33 | 0 | } |
34 | 121k | Debugger::enter(message, file, line); |
35 | 121k | throw AssertionViolationException(what(cond, file, line, text)); |
36 | 121k | } |
37 | | |
38 | | |
39 | | void Bugcheck::nullPointer(const char* ptr, const char* file, LineNumber line) |
40 | 0 | { |
41 | 0 | Debugger::enter(std::string("NULL pointer: ") + ptr, file, line); |
42 | 0 | throw NullPointerException(what(ptr, file, line)); |
43 | 0 | } |
44 | | |
45 | | |
46 | | void Bugcheck::bugcheck(const char* file, LineNumber line) |
47 | 0 | { |
48 | 0 | Debugger::enter("Bugcheck", file, line); |
49 | 0 | throw BugcheckException(what(0, file, line)); |
50 | 0 | } |
51 | | |
52 | | |
53 | | void Bugcheck::bugcheck(const char* msg, const char* file, LineNumber line) |
54 | 0 | { |
55 | 0 | std::string m("Bugcheck"); |
56 | 0 | if (msg) |
57 | 0 | { |
58 | 0 | m.append(": "); |
59 | 0 | m.append(msg); |
60 | 0 | } |
61 | 0 | Debugger::enter(m, file, line); |
62 | 0 | throw BugcheckException(what(msg, file, line)); |
63 | 0 | } |
64 | | |
65 | | |
66 | | void Bugcheck::unexpected(const char* file, LineNumber line) |
67 | 0 | { |
68 | | #ifdef _DEBUG |
69 | | try |
70 | | { |
71 | | std::string msg("Unexpected exception in noexcept function or destructor: "); |
72 | | try |
73 | | { |
74 | | throw; |
75 | | } |
76 | | catch (Poco::Exception& exc) |
77 | | { |
78 | | msg += exc.displayText(); |
79 | | } |
80 | | catch (std::exception& exc) |
81 | | { |
82 | | msg += exc.what(); |
83 | | } |
84 | | catch (...) |
85 | | { |
86 | | msg += "unknown exception"; |
87 | | } |
88 | | Debugger::enter(msg, file, line); |
89 | | } |
90 | | catch (...) |
91 | | { |
92 | | } |
93 | | #endif |
94 | 0 | } |
95 | | |
96 | | |
97 | | void Bugcheck::debugger(const char* file, LineNumber line) |
98 | 0 | { |
99 | 0 | Debugger::enter(file, line); |
100 | 0 | } |
101 | | |
102 | | |
103 | | void Bugcheck::debugger(const char* msg, const char* file, LineNumber line) |
104 | 0 | { |
105 | 0 | Debugger::enter(msg, file, line); |
106 | 0 | } |
107 | | |
108 | | |
109 | | std::string Bugcheck::what(const char* msg, const char* file, LineNumber line, const char* text) |
110 | 121k | { |
111 | 121k | std::ostringstream str; |
112 | 121k | if (msg) str << msg << " "; |
113 | 121k | if (text != NULL) str << "(" << text << ") "; |
114 | 121k | str << "in file \"" << file << "\", line " << line; |
115 | 121k | return str.str(); |
116 | 121k | } |
117 | | |
118 | | |
119 | | } // namespace Poco |