Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
aleph-exceptions.H
Go to the documentation of this file.
1
2/*
3 Aleph_w
4
5 Data structures & Algorithms
6 version 2.0.0b
7 https://github.com/lrleon/Aleph-w
8
9 This file is part of Aleph-w library
10
11 Copyright (c) 2002-2026 Leandro Rabindranath Leon
12
13 Permission is hereby granted, free of charge, to any person obtaining a copy
14 of this software and associated documentation files (the "Software"), to deal
15 in the Software without restriction, including without limitation the rights
16 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17 copies of the Software, and to permit persons to whom the Software is
18 furnished to do so, subject to the following conditions:
19
20 The above copyright notice and this permission notice shall be included in all
21 copies or substantial portions of the Software.
22
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 SOFTWARE.
30*/
31
32
88# ifndef ALEPH_EXCEPTIONS_H
89# define ALEPH_EXCEPTIONS_H
90
91# include <exception>
92# include <sstream>
93
94# include <ahUtils.H>
95
96// The classes are deprecated, and so are their uses here: they warn only
97// where the programs use them. The public macros are defined outside of
98// the regions without the warning, which, for GCC, cover what they spell
99# if defined(_MSC_VER) && !defined(__clang__)
100# pragma warning(push)
101# pragma warning(disable : 4996)
102# else
103# pragma GCC diagnostic push
104# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
105# endif
106
107# define ALEPH_EXCEPTIONS_DEPRECATED \
108 [[deprecated("aleph-exceptions.H goes in 8.0.0; use the macros of ah-errors.H instead")]]
109
119struct ALEPH_EXCEPTIONS_DEPRECATED AlephException : public std::runtime_error
120{
122 const size_t line_number = 0;
123
125 const std::string file_name = "No defined";
126
127 const std::string type = "No defined";
128 const std::string msg = "No defined";
129
130protected:
131
132 std::string category_msg = "No defined";
133
134private:
135
136 static std::string make_what(const std::string & category_msg,
137 size_t line_number,
138 const std::string & file_name,
139 const std::string & type,
140 const std::string & msg)
141 {
142 std::ostringstream s;
143 s << category_msg << "|" << file_name << "|" << line_number
144 << "|" << type << "|" << msg;
145 return s.str();
146 }
147
148public:
149
150 AlephException() : std::runtime_error(msg) {}
151
152 AlephException(const std::string & category_msg,
153 const size_t line_number,
154 const std::string & file_name,
155 const std::string & type,
156 const std::string & msg)
157 : runtime_error(make_what(category_msg, line_number, file_name, type, msg)),
158 line_number(line_number), file_name(file_name), type(type) {}
159};
160
161# if defined(_MSC_VER) && !defined(__clang__)
162# pragma warning(pop)
163# else
164# pragma GCC diagnostic pop
165# endif
166
178# define DEFINE_ALEPH_EXCEPTION(name, category_msg) \
179 struct name : public AlephException \
180 { \
181 name(const size_t line_number, \
182 const std::string & file_name, \
183 const std::string & type, \
184 const std::string & msg) \
185 : AlephException(#category_msg, line_number, file_name, type, msg) {} \
186 \
187 private: \
188 /* GCC does not warn of a deprecated base class: of this, it does */ \
189 using aleph_deprecated_base_ = AlephException; \
190 };
191
201# define ALEPHTHROW(type, msg) throw type(__LINE__, __FILE__, #type, msg)
202
203# if defined(_MSC_VER) && !defined(__clang__)
204# pragma warning(push)
205# pragma warning(disable : 4996)
206# else
207# pragma GCC diagnostic push
208# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
209# endif
210
211// The exceptions of Aleph, deprecated as AlephException
212# define ALEPH_DEFINE_DEPRECATED_EXCEPTION(name, category_msg) \
213 struct ALEPH_EXCEPTIONS_DEPRECATED name : public AlephException \
214 { \
215 name(const size_t line_number, \
216 const std::string & file_name, \
217 const std::string & type, \
218 const std::string & msg) \
219 : AlephException(#category_msg, line_number, file_name, type, msg) {} \
220 };
221
223 "minimum value is greater than maximum value");
228ALEPH_DEFINE_DEPRECATED_EXCEPTION(OutOfRange, "Value is out of allowed range");
231ALEPH_DEFINE_DEPRECATED_EXCEPTION(InvariantError, "A bug has been detected. "
232 "Please send a bug report to leandro.r.leon@gmail.com");
233ALEPH_DEFINE_DEPRECATED_EXCEPTION(SizeMismatch, "Sequences have different sizes");
234ALEPH_DEFINE_DEPRECATED_EXCEPTION(InvalidConversion, "failure in numeric conversion");
241ALEPH_DEFINE_DEPRECATED_EXCEPTION(InvalidRead, "Error while reading input stream");
243
244# undef ALEPH_DEFINE_DEPRECATED_EXCEPTION
245# undef ALEPH_EXCEPTIONS_DEPRECATED
246
247# if defined(_MSC_VER) && !defined(__clang__)
248# pragma warning(pop)
249# else
250# pragma GCC diagnostic pop
251# endif
252
253# endif
General utility functions and helpers.
#define ALEPH_EXCEPTIONS_DEPRECATED
#define ALEPH_DEFINE_DEPRECATED_EXCEPTION(name, category_msg)
STL namespace.
Aleph exception class.
static std::string make_what(const std::string &category_msg, size_t line_number, const std::string &file_name, const std::string &type, const std::string &msg)
AlephException(const std::string &category_msg, const size_t line_number, const std::string &file_name, const std::string &type, const std::string &msg)