1//
2// Exception.cpp
3//
4// Library: Foundation
5// Package: Core
6// Module: Exception
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/Exception.h"
16#include <typeinfo>
17
18
19namespace Poco {
20
21
22Exception::Exception(int otherCode): _pNested(0), _code(otherCode)
23{
24}
25
26
27Exception::Exception(const std::string& msg, int otherCode): _msg(msg), _pNested(0), _code(otherCode)
28{
29}
30
31
32Exception::Exception(const std::string& msg, const std::string& arg, int otherCode): _msg(msg), _pNested(0), _code(otherCode)
33{
34 if (!arg.empty())
35 {
36 _msg.append(": ");
37 _msg.append(arg);
38 }
39}
40
41
42Exception::Exception(const std::string& msg, const Exception& nestedException, int otherCode): _msg(msg), _pNested(nestedException.clone()), _code(otherCode)
43{
44}
45
46
47Exception::Exception(const Exception& exc):
48 std::exception(exc),
49 _msg(exc._msg),
50 _code(exc._code)
51{
52 _pNested = exc._pNested ? exc._pNested->clone() : 0;
53}
54
55
56Exception::~Exception() throw()
57{
58 delete _pNested;
59}
60
61
62Exception& Exception::operator = (const Exception& exc)
63{
64 if (&exc != this)
65 {
66 Exception* newPNested = exc._pNested ? exc._pNested->clone() : 0;
67 delete _pNested;
68 _msg = exc._msg;
69 _pNested = newPNested;
70 _code = exc._code;
71 }
72 return *this;
73}
74
75
76const char* Exception::name() const throw()
77{
78 return "Exception";
79}
80
81
82const char* Exception::className() const throw()
83{
84 return typeid(*this).name();
85}
86
87
88const char* Exception::what() const throw()
89{
90 return name();
91}
92
93
94std::string Exception::displayText() const
95{
96 std::string txt = name();
97 if (!_msg.empty())
98 {
99 txt.append(": ");
100 txt.append(_msg);
101 }
102 return txt;
103}
104
105
106void Exception::extendedMessage(const std::string& arg)
107{
108 if (!arg.empty())
109 {
110 if (!_msg.empty()) _msg.append(": ");
111 _msg.append(arg);
112 }
113}
114
115
116Exception* Exception::clone() const
117{
118 return new Exception(*this);
119}
120
121
122void Exception::rethrow() const
123{
124 throw *this;
125}
126
127
128POCO_IMPLEMENT_EXCEPTION(LogicException, Exception, "Logic exception")
129POCO_IMPLEMENT_EXCEPTION(AssertionViolationException, LogicException, "Assertion violation")
130POCO_IMPLEMENT_EXCEPTION(NullPointerException, LogicException, "Null pointer")
131POCO_IMPLEMENT_EXCEPTION(NullValueException, LogicException, "Null value")
132POCO_IMPLEMENT_EXCEPTION(BugcheckException, LogicException, "Bugcheck")
133POCO_IMPLEMENT_EXCEPTION(InvalidArgumentException, LogicException, "Invalid argument")
134POCO_IMPLEMENT_EXCEPTION(NotImplementedException, LogicException, "Not implemented")
135POCO_IMPLEMENT_EXCEPTION(RangeException, LogicException, "Out of range")
136POCO_IMPLEMENT_EXCEPTION(IllegalStateException, LogicException, "Illegal state")
137POCO_IMPLEMENT_EXCEPTION(InvalidAccessException, LogicException, "Invalid access")
138POCO_IMPLEMENT_EXCEPTION(SignalException, LogicException, "Signal received")
139POCO_IMPLEMENT_EXCEPTION(UnhandledException, LogicException, "Unhandled exception")
140
141POCO_IMPLEMENT_EXCEPTION(RuntimeException, Exception, "Runtime exception")
142POCO_IMPLEMENT_EXCEPTION(NotFoundException, RuntimeException, "Not found")
143POCO_IMPLEMENT_EXCEPTION(ExistsException, RuntimeException, "Exists")
144POCO_IMPLEMENT_EXCEPTION(TimeoutException, RuntimeException, "Timeout")
145POCO_IMPLEMENT_EXCEPTION(SystemException, RuntimeException, "System exception")
146POCO_IMPLEMENT_EXCEPTION(RegularExpressionException, RuntimeException, "Error in regular expression")
147POCO_IMPLEMENT_EXCEPTION(LibraryLoadException, RuntimeException, "Cannot load library")
148POCO_IMPLEMENT_EXCEPTION(LibraryAlreadyLoadedException, RuntimeException, "Library already loaded")
149POCO_IMPLEMENT_EXCEPTION(NoThreadAvailableException, RuntimeException, "No thread available")
150POCO_IMPLEMENT_EXCEPTION(PropertyNotSupportedException, RuntimeException, "Property not supported")
151POCO_IMPLEMENT_EXCEPTION(PoolOverflowException, RuntimeException, "Pool overflow")
152POCO_IMPLEMENT_EXCEPTION(NoPermissionException, RuntimeException, "No permission")
153POCO_IMPLEMENT_EXCEPTION(OutOfMemoryException, RuntimeException, "Out of memory")
154POCO_IMPLEMENT_EXCEPTION(DataException, RuntimeException, "Data error")
155
156POCO_IMPLEMENT_EXCEPTION(InterruptedException, RuntimeException, "Interrupted")
157POCO_IMPLEMENT_EXCEPTION(IndexOutOfBoundsException, RuntimeException, "Index out of bounds")
158POCO_IMPLEMENT_EXCEPTION(UnsupportedOperationException, RuntimeException, "Unsupported operation")
159POCO_IMPLEMENT_EXCEPTION(EmptyStackException, RuntimeException, "Empty stack")
160POCO_IMPLEMENT_EXCEPTION(StackOverflowException, RuntimeException, "Stack overflow")
161POCO_IMPLEMENT_EXCEPTION(ArithmeticException, RuntimeException, "Arithmetic error")
162
163POCO_IMPLEMENT_EXCEPTION(DataFormatException, DataException, "Bad data format")
164POCO_IMPLEMENT_EXCEPTION(SyntaxException, DataException, "Syntax error")
165POCO_IMPLEMENT_EXCEPTION(CircularReferenceException, DataException, "Circular reference")
166POCO_IMPLEMENT_EXCEPTION(PathSyntaxException, SyntaxException, "Bad path syntax")
167POCO_IMPLEMENT_EXCEPTION(IOException, RuntimeException, "I/O error")
168POCO_IMPLEMENT_EXCEPTION(ProtocolException, IOException, "Protocol error")
169POCO_IMPLEMENT_EXCEPTION(FileException, IOException, "File access error")
170POCO_IMPLEMENT_EXCEPTION(FileExistsException, FileException, "File exists")
171POCO_IMPLEMENT_EXCEPTION(FileNotFoundException, FileException, "File not found")
172POCO_IMPLEMENT_EXCEPTION(PathNotFoundException, FileException, "Path not found")
173POCO_IMPLEMENT_EXCEPTION(FileReadOnlyException, FileException, "File is read-only")
174POCO_IMPLEMENT_EXCEPTION(FileAccessDeniedException, FileException, "Access to file denied")
175POCO_IMPLEMENT_EXCEPTION(CreateFileException, FileException, "Cannot create file")
176POCO_IMPLEMENT_EXCEPTION(OpenFileException, FileException, "Cannot open file")
177POCO_IMPLEMENT_EXCEPTION(WriteFileException, FileException, "Cannot write file")
178POCO_IMPLEMENT_EXCEPTION(ReadFileException, FileException, "Cannot read file")
179POCO_IMPLEMENT_EXCEPTION(DirectoryNotEmptyException, FileException, "Directory not empty")
180POCO_IMPLEMENT_EXCEPTION(UnknownURISchemeException, RuntimeException, "Unknown URI scheme")
181POCO_IMPLEMENT_EXCEPTION(TooManyURIRedirectsException, RuntimeException, "Too many URI redirects")
182POCO_IMPLEMENT_EXCEPTION(URISyntaxException, SyntaxException, "Bad URI syntax")
183
184POCO_IMPLEMENT_EXCEPTION(ApplicationException, Exception, "Application exception")
185POCO_IMPLEMENT_EXCEPTION(BadCastException, RuntimeException, "Bad cast exception")
186
187
188} // namespace Poco
189