sptk2 logo
SPTK Home Page
Exception.h
1/*
2╔══════════════════════════════════════════════════════════════════════════════╗
3║ SIMPLY POWERFUL TOOLKIT (SPTK) ║
4╟──────────────────────────────────────────────────────────────────────────────╢
5║ copyright © 1999-2022 Alexey Parshin. All rights reserved. ║
6║ email alexeyp@gmail.com ║
7╚══════════════════════════════════════════════════════════════════════════════╝
8┌──────────────────────────────────────────────────────────────────────────────┐
9│ This library is free software; you can redistribute it and/or modify it │
10│ under the terms of the GNU Library General Public License as published by │
11│ the Free Software Foundation; either version 2 of the License, or (at your │
12│ option) any later version. │
13│ │
14│ This library is distributed in the hope that it will be useful, but │
15│ WITHOUT ANY WARRANTY; without even the implied warranty of │
16│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library │
17│ General Public License for more details. │
18│ │
19│ You should have received a copy of the GNU Library General Public License │
20│ along with this library; if not, write to the Free Software Foundation, │
21│ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. │
22│ │
23│ Please report all bugs and problems to alexeyp@gmail.com. │
24└──────────────────────────────────────────────────────────────────────────────┘
25*/
26
27#pragma once
28
29#include <sptk5/Strings.h>
30#include <sptk5/sptk.h>
31#include <sstream>
32#include <stdexcept>
33
34namespace sptk {
35
36#ifndef _WIN32
37#define DOESNT_THROW noexcept
38#else
39#define DOESNT_THROW throw()
40#endif
41
55class SP_EXPORT Exception : public std::exception
56{
60 String m_file;
61
65 int m_line;
66
70 String m_text;
71
75 String m_description;
76
80 String m_fullMessage;
81
82public:
90 explicit Exception(const String& text, const fs::path& file = std::string(), int line = 0, const String& description = String()) DOESNT_THROW;
91
95 const char* what() const DOESNT_THROW override;
96
100 String message() const;
101
105 String file() const;
106
110 int line() const;
111
115 String description() const;
116};
117
123class SP_EXPORT TimeoutException : public Exception
124{
125public:
133 TimeoutException(const String& text, const fs::path& file = std::string(), int line = 0, const String& description = String()) DOESNT_THROW;
134
139 TimeoutException(const TimeoutException& other) = default;
140};
141
147class SP_EXPORT ConnectionException : public Exception
148{
149public:
157 ConnectionException(const String& text, const fs::path& file = std::string(), int line = 0, const String& description = String()) DOESNT_THROW;
158
164};
165
171class SP_EXPORT DatabaseException : public Exception
172{
173public:
181 DatabaseException(const String& text, const fs::path& file = std::string(), int line = 0, const String& description = String()) DOESNT_THROW;
182
187 DatabaseException(const DatabaseException& other) = default;
188};
189
195class SP_EXPORT SOAPException : public Exception
196{
197public:
205 SOAPException(const String& text, const fs::path& file = std::string(), int line = 0, const String& description = String()) DOESNT_THROW;
206
211 SOAPException(const SOAPException& other) = default;
212};
213
219class SP_EXPORT HTTPException : public Exception
220{
221 size_t m_statusCode;
222 String m_statusText;
223public:
232 HTTPException(size_t statusCode, const String& text, const fs::path& file = std::string(), int line = 0, const String& description = String()) DOESNT_THROW;
233
238 HTTPException(const HTTPException& other) = default;
239
244 size_t statusCode() const
245 {
246 return m_statusCode;
247 }
248
254 {
255 return m_statusText;
256 }
257
263 static String httpResponseStatus(size_t statusCode);
264};
265
274#define throwException(msg) \
275 { \
276 std::stringstream err; \
277 err << msg; \
278 throw sptk::Exception(err.str(), __FILE__, __LINE__); \
279 }
280
284#define throwTimeoutException(msg) \
285 { \
286 std::stringstream err; \
287 err << msg; \
288 throw sptk::TimeoutException(err.str(), __FILE__, __LINE__); \
289 }
290
294#define throwConnectionException(msg) \
295 { \
296 std::stringstream err; \
297 err << msg; \
298 throw sptk::ConnectionException(err.str(), __FILE__, __LINE__); \
299 }
300
304#define throwDatabaseException(msg) \
305 { \
306 std::stringstream err; \
307 err << msg; \
308 throw sptk::DatabaseException(err.str(), __FILE__, __LINE__); \
309 }
310
314#define throwSOAPException(msg) \
315 { \
316 std::stringstream err; \
317 err << msg; \
318 throw sptk::SOAPException(err.str(), __FILE__, __LINE__); \
319 }
320
324} // namespace sptk
Connection exception.
Definition: Exception.h:148
ConnectionException(const String &text, const fs::path &file=std::string(), int line=0, const String &description=String()) DOESNT_THROW
Database operation exception.
Definition: Exception.h:172
DatabaseException(const String &text, const fs::path &file=std::string(), int line=0, const String &description=String()) DOESNT_THROW
Constructor.
SPTK generic exception class.
Definition: Exception.h:56
Exception(const String &text, const fs::path &file=std::string(), int line=0, const String &description=String()) DOESNT_THROW
Constructor.
SOAP exception.
Definition: Exception.h:220
static String httpResponseStatus(size_t statusCode)
String statusText() const
Definition: Exception.h:253
HTTPException(size_t statusCode, const String &text, const fs::path &file=std::string(), int line=0, const String &description=String()) DOESNT_THROW
SOAP exception.
Definition: Exception.h:196
SOAPException(const String &text, const fs::path &file=std::string(), int line=0, const String &description=String()) DOESNT_THROW
Definition: String.h:49
Timeout exception.
Definition: Exception.h:124
TimeoutException(const String &text, const fs::path &file=std::string(), int line=0, const String &description=String()) DOESNT_THROW

Fri Oct 14 2022 09:58:31: SPTK 5.4.1