Aleph-w 3.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
80# ifndef ALEPH_EXCEPTIONS_H
81# define ALEPH_EXCEPTIONS_H
82
83# include <exception>
84# include <sstream>
85
86# include <ahUtils.H>
87
95struct AlephException : public std::runtime_error
96{
98 const size_t line_number = 0;
99
101 const std::string file_name = "No defined";
102
103 const std::string type = "No defined";
104 const std::string msg = "No defined";
105
106protected:
107
108 std::string category_msg = "No defined";
109
110private:
111
112 static std::string make_what(const std::string & category_msg,
113 size_t line_number,
114 const std::string & file_name,
115 const std::string & type,
116 const std::string & msg)
117 {
118 std::ostringstream s;
119 s << category_msg << "|" << file_name << "|" << line_number
120 << "|" << type << "|" << msg;
121 return s.str();
122 }
123
124public:
125
126 AlephException() : std::runtime_error(msg) {}
127
128 AlephException(const std::string & category_msg,
129 const size_t line_number,
130 const std::string & file_name,
131 const std::string & type,
132 const std::string & msg)
133 : runtime_error(make_what(category_msg, line_number, file_name, type, msg)),
135};
136
145# define DEFINE_ALEPH_EXCEPTION(name, category_msg) \
146 struct name : public AlephException \
147 { \
148 name(const size_t line_number, \
149 const std::string & file_name, \
150 const std::string & type, \
151 const std::string & msg) \
152 : AlephException(#category_msg, line_number, file_name, type, msg) {} \
153 };
154
162# define ALEPHTHROW(type, msg) throw type(__LINE__, __FILE__, #type, msg)
163
165 "minimum value is greater than maximum value");
170DEFINE_ALEPH_EXCEPTION(OutOfRange, "Value is out of allowed range");
172DEFINE_ALEPH_EXCEPTION(CommandLineError, "error parsing command line");
173DEFINE_ALEPH_EXCEPTION(InvariantError, "A bug has been detected. "
174 "Please send a bug report to leandro.r.leon@gmail.com");
175DEFINE_ALEPH_EXCEPTION(SizeMismatch, "Sequences have different sizes");
176DEFINE_ALEPH_EXCEPTION(InvalidConversion, "failure in numeric conversion");
183DEFINE_ALEPH_EXCEPTION(InvalidRead, "Error while reading input stream");
185
186# endif
General utility functions and helpers.
#define DEFINE_ALEPH_EXCEPTION(name, category_msg)
Define a new exception.
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)
std::string category_msg
Message describing the error.
const std::string msg
Type name.
const std::string file_name
file name where the exception was thrown
const size_t line_number
Line number of source file where the exception was thrown.
const std::string type
AlephException(const std::string &category_msg, const size_t line_number, const std::string &file_name, const std::string &type, const std::string &msg)