Navigation

Main Page
Download
Support
Installation
Tutorial
Examples
Reference Manual
   Version 1.0.6dev
      Class Index
      File List
   Version 1.0.6
   Version 1.0.5new_solver
   Version 1.0.5dev
   Version 1.0.5b
   Version 1.0.4dev
   Version 1.0.4
Publications


Hosted by Get Ion Beam Simulator at SourceForge.net. Fast, secure and Free Open Source software downloads
error.hpp
Go to the documentation of this file.
1 
5 /* Copyright (c) 2005-2012 Taneli Kalvas. All rights reserved.
6  *
7  * You can redistribute this software and/or modify it under the terms
8  * of the GNU General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * This library is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this library (file "COPYING" included in the package);
19  * if not, write to the Free Software Foundation, Inc., 51 Franklin
20  * Street, Fifth Floor, Boston, MA 02110-1301 USA
21  *
22  * If you have questions about your rights to use or distribute this
23  * software, please contact Berkeley Lab's Technology Transfer
24  * Department at TTD@lbl.gov. Other questions, comments and bug
25  * reports should be sent directly to the author via email at
26  * taneli.kalvas@jyu.fi.
27  *
28  * NOTICE. This software was developed under partial funding from the
29  * U.S. Department of Energy. As such, the U.S. Government has been
30  * granted for itself and others acting on its behalf a paid-up,
31  * nonexclusive, irrevocable, worldwide license in the Software to
32  * reproduce, prepare derivative works, and perform publicly and
33  * display publicly. Beginning five (5) years after the date
34  * permission to assert copyright is obtained from the U.S. Department
35  * of Energy, and subject to any subsequent five (5) year renewals,
36  * the U.S. Government is granted for itself and others acting on its
37  * behalf a paid-up, nonexclusive, irrevocable, worldwide license in
38  * the Software to reproduce, prepare derivative works, distribute
39  * copies to the public, perform publicly and display publicly, and to
40  * permit others to do so.
41  */
42 
43 #ifndef ERROR_HPP
44 #define ERROR_HPP 1
45 
46 
47 #include "config.h"
48 #include <string>
49 #include <cstring>
50 #include <stdlib.h>
51 #include <stdint.h>
52 #include <stdlib.h>
53 #include <stdio.h>
54 #include <sstream>
55 #include <errno.h>
56 #include <signal.h>
57 
58 
61 template <class T>
62 inline std::string to_string( const T& t )
63 {
64  std::stringstream ss;
65  ss << t;
66  return( ss.str() );
67 }
68 
69 
72 template <class T>
73 inline std::wstring to_wstring( const T& t )
74 {
75  std::wstringstream ss;
76  ss << t;
77  return( ss.str() );
78 }
79 
80 
83 #define ERROR_LOCATION ErrorLocation( __FILE__, __LINE__, __func__ )
84 
85 
94 
95  const char *_file;
96  int _line;
97  const char *_func;
98 
99 public:
100 
105  ErrorLocation();
106 
111  ErrorLocation( const char *file, int line, const char *func );
112 
115  std::string file( void );
116 
119  int line( void );
120 
123  std::string func( void );
124 };
125 
126 
133 
134  void *_traceaddress[25];
135  int _tracecount;
136 
137 public:
138 
143  ExceptionTracer();
144 
147  void print_trace( std::ostream &os );
148 };
149 
150 
153 class Error : public ExceptionTracer {
154 
155  ErrorLocation _loc;
156 
157 protected:
158 
159  std::string _error_str;
160 
161 public:
162 
165  Error();
166 
169  Error( const std::string &str );
170 
173  Error( const ErrorLocation &loc );
174 
178  Error( const ErrorLocation &loc, const std::string &str );
179 
182  std::string get_error_message( void );
183 
190  void print_error_message( std::ostream &os, bool traceprint = true );
191 };
192 
193 
196 class ErrorNoMem : public Error {
197 
198 public:
199 
204  ErrorNoMem( const ErrorLocation &loc );
205 
208  ErrorNoMem( const ErrorLocation &loc, const std::string &str );
209 };
210 
211 
214 class ErrorErrno : public Error {
215 
216  int _ierrno;
217 
218 public:
219 
223  ErrorErrno( const ErrorLocation &loc );
224 };
225 
226 
229 class ErrorUnimplemented : public Error {
230 
231 public:
232 
237  ErrorUnimplemented( const ErrorLocation &loc );
238 
241  ErrorUnimplemented( const ErrorLocation &loc, const std::string &str );
242 };
243 
244 
247 class ErrorAssert : public Error {
248 
249 public:
250 
255  ErrorAssert( const ErrorLocation &loc );
256 
259  ErrorAssert( const ErrorLocation &loc, const std::string &str );
260 };
261 
262 
265 class ErrorDim : public Error {
266 
267 public:
268 
273  ErrorDim( const ErrorLocation &loc );
274 
277  ErrorDim( const ErrorLocation &loc, const std::string &str );
278 };
279 
280 
283 class ErrorRange : public Error {
284 
285 public:
286 
292  ErrorRange( const ErrorLocation &loc,
293  uint32_t i, uint32_t n,
294  uint32_t j, uint32_t m );
295 
300  ErrorRange( const ErrorLocation &loc, uint32_t i, uint32_t n );
301 
307  ErrorRange( const ErrorLocation &loc, uint32_t i, uint32_t n, const std::string &str );
308 
311  ErrorRange( const ErrorLocation &loc, const std::string &str );
312 };
313 
314 
318 
319 public:
320 
321 #if defined(_GNU_SOURCE) && defined(HAVE_SIGINFO_T)
324  static void signal_handler_SIGSEGV( int signum, siginfo_t *info, void *ptr );
325 
328  static void signal_handler_SIGTERM( int signum, siginfo_t *info, void *ptr );
329 #else
332  static void signal_handler_SIGTERM( int signum );
333 #endif
334 };
335 
336 
337 #endif
338 
Error class to use if impossible things happen
Definition: error.hpp:247
ErrorAssert(const ErrorLocation &loc)
Constructor for assert error with standard error message.
Definition: error.cpp:320
Error class for dimension mismatch errors.
Definition: error.hpp:265
ErrorDim(const ErrorLocation &loc)
Constructor for dimension mismatch error with standard error message.
Definition: error.cpp:335
Error class for C-style errno errors.
Definition: error.hpp:214
ErrorErrno(const ErrorLocation &loc)
Constructor for errno based error with standard error message from errno database.
Definition: error.cpp:349
Error location class.
Definition: error.hpp:93
int line(void)
Return line number of location.
Definition: error.cpp:236
std::string func(void)
Return function name of location.
Definition: error.cpp:242
std::string file(void)
Return file name of location.
Definition: error.cpp:230
ErrorLocation()
Default constructor for error location.
Definition: error.cpp:216
Error class for memory allocation errors.
Definition: error.hpp:196
ErrorNoMem(const ErrorLocation &loc)
Constructor for memory allocation error with standard error message.
Definition: error.cpp:291
Error class for index range checking errors.
Definition: error.hpp:283
ErrorRange(const ErrorLocation &loc, uint32_t i, uint32_t n, uint32_t j, uint32_t m)
Constructor for error message for two dimensional indexing error.
Definition: error.cpp:369
Error class to use if requested feature is unimplemented.
Definition: error.hpp:229
ErrorUnimplemented(const ErrorLocation &loc)
Constructor for unimplemented feature error with standard error message.
Definition: error.cpp:305
Basic error class.
Definition: error.hpp:153
void print_error_message(std::ostream &os, bool traceprint=true)
Print a standard error message to os.
Definition: error.cpp:275
Error()
Default constructor for error class.
Definition: error.cpp:248
std::string get_error_message(void)
Return error message.
Definition: error.cpp:285
Exception backtrace.
Definition: error.hpp:132
void print_trace(std::ostream &os)
Print the backtrace to os.
Definition: error.cpp:127
ExceptionTracer()
Default constructor for exception tracer. Saves the backtrace of the program at this location for pri...
Definition: error.cpp:84
Signal handler.
Definition: error.hpp:317
static void signal_handler_SIGTERM(int signum)
Signal handler function for SIGTERM.
Definition: error.cpp:149
std::string to_string(const T &t)
Function for converting a type to string.
Definition: error.hpp:62
std::wstring to_wstring(const T &t)
Function for converting a type to string.
Definition: error.hpp:73


Reference manual for Ion Beam Simulator 1.0.6dev
Generated by Doxygen 1.9.1 on Thu Sep 11 2025 09:37:24.