Navigation

Main Page
Download
Support
Installation
Tutorial
Examples
Reference Manual
   Version 1.0.5new_solver
      Class Index
      File List
   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 #define ERROR_LOCATION ErrorLocation( __FILE__, __LINE__, __func__ )
73 
74 
83 
84  const char *_file;
85  int _line;
86  const char *_func;
87 
88 public:
89 
94  ErrorLocation();
95 
100  ErrorLocation( const char *file, int line, const char *func );
101 
104  std::string file( void );
105 
108  int line( void );
109 
112  std::string func( void );
113 };
114 
115 
122 
123  void *_traceaddress[25];
124  int _tracecount;
125 
126 public:
127 
132  ExceptionTracer();
133 
136  void print_trace( std::ostream &os );
137 };
138 
139 
142 class Error : public ExceptionTracer {
143 
144  ErrorLocation _loc;
145 
146 protected:
147 
148  std::string _error_str;
149 
150 public:
151 
154  Error();
155 
158  Error( const std::string &str );
159 
162  Error( const ErrorLocation &loc );
163 
167  Error( const ErrorLocation &loc, const std::string &str );
168 
171  std::string get_error_message( void );
172 
179  void print_error_message( std::ostream &os, bool traceprint = true );
180 };
181 
182 
185 class ErrorNoMem : public Error {
186 
187 public:
188 
193  ErrorNoMem( const ErrorLocation &loc );
194 
197  ErrorNoMem( const ErrorLocation &loc, const std::string &str );
198 };
199 
200 
203 class ErrorErrno : public Error {
204 
205  int _ierrno;
206 
207 public:
208 
212  ErrorErrno( const ErrorLocation &loc );
213 };
214 
215 
218 class ErrorUnimplemented : public Error {
219 
220 public:
221 
226  ErrorUnimplemented( const ErrorLocation &loc );
227 
230  ErrorUnimplemented( const ErrorLocation &loc, const std::string &str );
231 };
232 
233 
236 class ErrorAssert : public Error {
237 
238 public:
239 
244  ErrorAssert( const ErrorLocation &loc );
245 
248  ErrorAssert( const ErrorLocation &loc, const std::string &str );
249 };
250 
251 
254 class ErrorDim : public Error {
255 
256 public:
257 
262  ErrorDim( const ErrorLocation &loc );
263 
266  ErrorDim( const ErrorLocation &loc, const std::string &str );
267 };
268 
269 
272 class ErrorRange : public Error {
273 
274 public:
275 
281  ErrorRange( const ErrorLocation &loc,
282  uint32_t i, uint32_t n,
283  uint32_t j, uint32_t m );
284 
289  ErrorRange( const ErrorLocation &loc, uint32_t i, uint32_t n );
290 
296  ErrorRange( const ErrorLocation &loc, uint32_t i, uint32_t n, const std::string &str );
297 
300  ErrorRange( const ErrorLocation &loc, const std::string &str );
301 };
302 
303 
307 
308 public:
309 
310 #if defined(_GNU_SOURCE) && defined(HAVE_SIGINFO_T)
311 
313  static void signal_handler_SIGSEGV( int signum, siginfo_t *info, void *ptr );
314 
317  static void signal_handler_SIGTERM( int signum, siginfo_t *info, void *ptr );
318 #else
319 
321  static void signal_handler_SIGTERM( int signum );
322 #endif
323 };
324 
325 
326 #endif
327 
ErrorErrno(const ErrorLocation &loc)
Constructor for errno based error with standard error message from errno database.
Definition: error.cpp:348
Error()
Default constructor for error class.
Definition: error.cpp:247
ErrorLocation()
Default constructor for error location.
Definition: error.cpp:215
Basic error class.
Definition: error.hpp:142
void print_trace(std::ostream &os)
Print the backtrace to os.
Definition: error.cpp:126
void print_error_message(std::ostream &os, bool traceprint=true)
Print a standard error message to os.
Definition: error.cpp:274
Error class for dimension mismatch errors.
Definition: error.hpp:254
ErrorDim(const ErrorLocation &loc)
Constructor for dimension mismatch error with standard error message.
Definition: error.cpp:334
Error class to use if impossible things happen
Definition: error.hpp:236
std::string to_string(const T &t)
Function for converting a type to string.
Definition: error.hpp:62
ErrorNoMem(const ErrorLocation &loc)
Constructor for memory allocation error with standard error message.
Definition: error.cpp:290
ErrorAssert(const ErrorLocation &loc)
Constructor for assert error with standard error message.
Definition: error.cpp:319
Signal handler.
Definition: error.hpp:306
static void signal_handler_SIGTERM(int signum)
Signal handler function for SIGTERM.
Definition: error.cpp:148
Error class for C-style errno errors.
Definition: error.hpp:203
std::string get_error_message(void)
Return error message.
Definition: error.cpp:284
int line(void)
Return line number of location.
Definition: error.cpp:235
Error class to use if requested feature is unimplemented.
Definition: error.hpp:218
ExceptionTracer()
Default constructor for exception tracer. Saves the backtrace of the program at this location for pri...
Definition: error.cpp:83
Error class for memory allocation errors.
Definition: error.hpp:185
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:367
ErrorUnimplemented(const ErrorLocation &loc)
Constructor for unimplemented feature error with standard error message.
Definition: error.cpp:304
Error class for index range checking errors.
Definition: error.hpp:272
Exception backtrace.
Definition: error.hpp:121
Error location class.
Definition: error.hpp:82
std::string func(void)
Return function name of location.
Definition: error.cpp:241
std::string file(void)
Return file name of location.
Definition: error.cpp:229


Reference manual for Ion Beam Simulator 1.0.5new_solver
Generated by Doxygen 1.8.5 on Tue May 19 2015 09:15:42.