Webdar 1.0.0
Web user interface to libdar
exceptions.hpp
1/*********************************************************************/
2// webdar - a web server and interface program to libdar
3// Copyright (C) 2013-2025 Denis Corbin
4//
5// This file is part of Webdar
6//
7// Webdar is free software: you can redistribute it and/or modify
8// it under the terms of the GNU General Public License as published by
9// the Free Software Foundation, either version 3 of the License, or
10// (at your option) any later version.
11//
12// Webdar is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with Webdar. If not, see <http://www.gnu.org/licenses/>
19//
20//----
21// to contact the author: dar.linux@free.fr
22/*********************************************************************/
23
24#ifndef EXCEPTIONS_HPP
25#define EXCEPTIONS_HPP
26
27 // C system header files
28#include "my_config.h"
29extern "C"
30{
31#if HAVE_STRING_H
32#include <string.h>
33#endif
34}
35
36 // C++ system header files
37#include <string>
38#include <new>
39
40 // libraries header files
41#include <dar/libdar.hpp>
42
43
45
47{
48public:
49 exception_base(const std::string & x_msg) {msg = x_msg; };
50
51 virtual ~exception_base() {};
52
53 const std::string & get_message() const { return msg; };
54 void change_message(const std::string & x_msg) { msg = x_msg; };
55
56 virtual exception_base *clone() const = 0;
57
58private:
59 std::string msg;
60};
61
62
63
65
67{
68public:
69 exception_memory() : exception_base("lack of memory") {};
70
71protected:
72 virtual exception_base *clone() const override;
73};
74
75template<class T> exception_base *cloner(void * const ptr) { exception_base *ret = new (std::nothrow) T(*(reinterpret_cast<T const *>(ptr))); if(ret == nullptr) throw exception_memory(); return ret; };
76
77inline exception_base * exception_memory::clone() const { return cloner<exception_memory>((void *)this); };
78
80
81#define WEBDAR_BUG exception_bug(__FILE__, __LINE__)
82
84
86{
87public:
88 exception_bug(const std::string & file, int line) : exception_base(std::string("WEBDAR: BUG MET IN File ") + file + std::string(" line ") + std::to_string(line)) {};
89
90protected:
91 virtual exception_base *clone() const override { return cloner<exception_bug>((void *)this); };
92};
93
94
96
98{
99public:
100 exception_system(const std::string & context, int error_code);
101
102protected:
103 virtual exception_base *clone() const override { return cloner<exception_system>((void *)this); };
104};
105
107
109{
110public:
111 exception_range(const std::string & msg): exception_base(msg) {};
112
113protected:
114 virtual exception_base *clone() const override { return cloner<exception_range>((void *)this); };
115};
116
118
125{
126public:
127 exception_input(const std::string & msg, unsigned int error_code): exception_base(msg) {err = error_code; };
128 unsigned int get_error_code() const { return err; };
129
130protected:
131 virtual exception_base *clone() const override { return cloner<exception_input>((void *)this); };
132
133private:
134 unsigned int err;
135};
136
137
139
141{
142public:
143 exception_feature(const std::string & feature_name): exception_base(std::string("Unimplemented feature: ") + feature_name) {};
144
145protected:
146 virtual exception_base *clone() const override { return cloner<exception_feature>((void *)this); };
147};
148
150
152{
153public:
154 exception_libcall(const libdar::Egeneric & e);
155
156protected:
157 virtual exception_base *clone() const override { return cloner<exception_libcall>((void *)this); };
158};
159
161
163{
164public:
166
167protected:
168 virtual exception_base *clone() const override { return cloner<exception_openssl>((void *)this); };
169
170private:
171 static constexpr unsigned int ERR_BUF_LEN = 1024;
172
173 static std::string get_ssl_error();
174};
175
177
179{
180public:
181 exception_signal(): exception_base("system call interruted by a signal") {};
182
183protected:
184 virtual exception_base *clone() const override { return cloner<exception_signal>((void *)this); };
185};
186
187
188extern void throw_as_most_derivated_class(exception_base *ebase);
189
190#endif
pure virtual class parent of all webdar exceptions
Definition: exceptions.hpp:47
class used to signal bug condition
Definition: exceptions.hpp:86
exception used to report an non-implemented feature
Definition: exceptions.hpp:141
exception used to report an request error from the http client
Definition: exceptions.hpp:125
transcription of libdar exception into the webdar exception type
Definition: exceptions.hpp:152
exception used to report memory allocation failures
Definition: exceptions.hpp:67
class used to signal SSL related errors
Definition: exceptions.hpp:163
exception used to report out or range value or argument
Definition: exceptions.hpp:109
class used to propagate the reception of a signal by the current process/thread
Definition: exceptions.hpp:179
exception used to report operating system errors
Definition: exceptions.hpp:98