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
21namespace Poco {
22
23
24void Bugcheck::assertion(const char* cond, const char* file, int line, const char* text)
25{
26 std::string message("Assertion violation: ");
27 message += cond;
28 if (text)
29 {
30 message += " (";
31 message += text;
32 message += ")";
33 }
34 Debugger::enter(message, file, line);
35 throw AssertionViolationException(what(cond, file, line, text));
36}
37
38
39void Bugcheck::nullPointer(const char* ptr, const char* file, int line)
40{
41 Debugger::enter(std::string("NULL pointer: ") + ptr, file, line);
42 throw NullPointerException(what(ptr, file, line));
43}
44
45
46void Bugcheck::bugcheck(const char* file, int line)
47{
48 Debugger::enter("Bugcheck", file, line);
49 throw BugcheckException(what(0, file, line));
50}
51
52
53void Bugcheck::bugcheck(const char* msg, const char* file, int line)
54{
55 std::string m("Bugcheck");
56 if (msg)
57 {
58 m.append(": ");
59 m.append(msg);
60 }
61 Debugger::enter(m, file, line);
62 throw BugcheckException(what(msg, file, line));
63}
64
65
66void Bugcheck::unexpected(const char* file, int line)
67{
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}
95
96
97void Bugcheck::debugger(const char* file, int line)
98{
99 Debugger::enter(file, line);
100}
101
102
103void Bugcheck::debugger(const char* msg, const char* file, int line)
104{
105 Debugger::enter(msg, file, line);
106}
107
108
109std::string Bugcheck::what(const char* msg, const char* file, int line, const char* text)
110{
111 std::ostringstream str;
112 if (msg) str << msg << " ";
113 if (text != NULL) str << "(" << text << ") ";
114 str << "in file \"" << file << "\", line " << line;
115 return str.str();
116}
117
118
119} // namespace Poco
120