ALL 0.9.3
A Loadbalacing Library
Loading...
Searching...
No Matches
ALL_CustomExceptions.hpp
Go to the documentation of this file.
1/*
2Copyright 2018-2020 Rene Halver, Forschungszentrum Juelich GmbH, Germany
3Copyright 2018-2020 Godehard Sutmann, Forschungszentrum Juelich GmbH, Germany
4
5Redistribution and use in source and binary forms, with or without modification,
6are permitted provided that the following conditions are met:
7
81. Redistributions of source code must retain the above copyright notice, this
9 list of conditions and the following disclaimer.
10
112. Redistributions in binary form must reproduce the above copyright notice,
12this list of conditions and the following disclaimer in the documentation and/or
13 other materials provided with the distribution.
14
153. Neither the name of the copyright holder nor the names of its contributors
16may be used to endorse or promote products derived from this software without
17 specific prior written permission.
18
19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29*/
30
31#ifndef ALL_CUSTOM_EXCEPTIONS_INC
32#define ALL_CUSTOM_EXCEPTIONS_INC
33
34#include <exception>
35#include <sstream>
36#include <string>
37
38namespace ALL {
39
41struct CustomException : public std::exception {
42protected:
44 const char *file;
46 const char *func;
48 int line;
50 const char *info;
52 const char *loc_desc;
54 std::string error_msg;
66
68
69public:
76 CustomException(const char *file_ = "", const char *f_ = "", int l_ = -1,
77 const char *i_ = "",
78 const char *loc_desc_ = "ALLCustomException",
79 const ErrorID error_id_ = ErrorID::Generic)
80 : file(file_), func(f_), line(l_), info(i_), loc_desc(loc_desc_), error_id(error_id_) {
81 std::stringstream ss;
82 ss << loc_desc << ": " << info << "\n"
83 << "Function: " << func << "\n"
84 << "File: " << file << "\n"
85 << "Line: " << line << "\n";
86 error_msg = ss.str();
87 }
88
90 const char *get_func() const { return func; }
91
94 int get_line() const { return line; }
95
99 const char *get_info() { return info; }
100
103 virtual const char *what() const throw() { return error_msg.c_str(); }
104
107 int get_error_id() { return static_cast<int>(error_id); }
108};
109
112public:
120 const char *file_, const char *f_, int l_,
121 const char *i_ = "Dimension missmatch in Point objects.",
122 const char *loc_desc_ = "ALLPointDimMissmatchException",
124 : CustomException(file_, f_, l_, i_, loc_desc_, error_id_) {}
125};
126
127// Execption to be used for invalid Communicators in a load-balancing method
129public:
137 const char *file_, const char *f_, int l_,
138 const char *i_ = "Type of MPI communicator not valid.",
139 const char *loc_desc_ = "ALLCommTypeInvalidException",
140 const ErrorID error_id_ = ErrorID::InvalidCommType)
141 : CustomException(file_, f_, l_, i_, loc_desc_, error_id_) {}
142};
143
144// Execption to be used for invalid parameters in any type of classes
146public:
154 const char *file_, const char *f_ = "", int l_ = -1,
155 const char *i_ = "Invalid argument given.",
156 const char *loc_desc_ = "ALLInvalidArgumentException",
157 const ErrorID error_id_ = ErrorID::InvalidArgument)
158 : CustomException(file_, f_, l_, i_, loc_desc_, error_id_) {}
159};
160
161// Execption to be used if an array went out of bounds
163public:
171 const char *file_, const char *f_ = "", int l_ = -1,
172 const char *i_ = "Access to array out of bounds.",
173 const char *loc_desc_ = "ALLOutOfBoundsErrorException",
174 const ErrorID error_id_ = ErrorID::OutOfBounds)
175 : CustomException(file_, f_, l_, i_, loc_desc_, error_id_) {}
176};
177
178// Execption to be used if an internal error has occured
180public:
188 const char *file_, const char *f_ = "", int l_ = -1,
189 const char *i_ = "Internal error occured, see description.",
190 const char *loc_desc_ = "ALLInternalErrorException",
191 const ErrorID error_id_ = ErrorID::InternalError)
192 : CustomException(file_, f_, l_, i_, loc_desc_, error_id_) {}
193};
194
195// Execption to be used if a filesystem error has occured
197public:
205 const char *file_, const char *f_ = "", int l_ = -1,
206 const char *i_ = "Filesystem error occured, see description.",
207 const char *loc_desc_ = "ALLFilesystemErrorException",
208 const ErrorID error_id_ = ErrorID::FilesystemError)
209 : CustomException(file_, f_, l_, i_, loc_desc_, error_id_) {}
210};
211
212}//namespace ALL
213
214#endif
Definition ALL.hpp:75
ErrorID error_id
error identificator retrieved by Fortran
const char * loc_desc
name of the exception
const char * info
information on the exception
CustomException(const char *file_="", const char *f_="", int l_=-1, const char *i_="", const char *loc_desc_="ALLCustomException", const ErrorID error_id_=ErrorID::Generic)
virtual const char * what() const
std::string error_msg
error message
const char * file
file the exception occured in
const char * func
function the exception occured in
const char * get_func() const
int line
line the exception occured in
FilesystemErrorException(const char *file_, const char *f_="", int l_=-1, const char *i_="Filesystem error occured, see description.", const char *loc_desc_="ALLFilesystemErrorException", const ErrorID error_id_=ErrorID::FilesystemError)
InternalErrorException(const char *file_, const char *f_="", int l_=-1, const char *i_="Internal error occured, see description.", const char *loc_desc_="ALLInternalErrorException", const ErrorID error_id_=ErrorID::InternalError)
InvalidArgumentException(const char *file_, const char *f_="", int l_=-1, const char *i_="Invalid argument given.", const char *loc_desc_="ALLInvalidArgumentException", const ErrorID error_id_=ErrorID::InvalidArgument)
InvalidCommTypeException(const char *file_, const char *f_, int l_, const char *i_="Type of MPI communicator not valid.", const char *loc_desc_="ALLCommTypeInvalidException", const ErrorID error_id_=ErrorID::InvalidCommType)
OutOfBoundsException(const char *file_, const char *f_="", int l_=-1, const char *i_="Access to array out of bounds.", const char *loc_desc_="ALLOutOfBoundsErrorException", const ErrorID error_id_=ErrorID::OutOfBounds)
PointDimensionMissmatchException(const char *file_, const char *f_, int l_, const char *i_="Dimension missmatch in Point objects.", const char *loc_desc_="ALLPointDimMissmatchException", const ErrorID error_id_=ErrorID::PointDimensionMissmatch)