error.h
Go to the documentation of this file.
1 /*
2  @copyright Russell Standish 2000-2013
3  @author Russell Standish
4  This file is part of EcoLab
5 
6  Open source licensed under the MIT license. See LICENSE for details.
7 */
8 
12 #ifndef ERROR_H
13 #define ERROR_H
14 
15 /* error handling */
16 #include <exception>
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <stdarg.h>
20 #include <string.h>
21 
22 namespace ecolab
23 {
25  class error: public std::exception
26  {
27  char errstring[200]; /* I hope this will always be large enough */
28  void abort_if_debug()
29  {
30  /* A partial fix for icc's buggy exception handling - at least print the error message */
31 #if __ICC==800
32  fputs(errstring,stderr);
33 #endif
34 #ifndef NDEBUG
35  fputs(errstring,stderr);
36  // abort(); // do catch catch in gdb instead
37 #endif
38  }
39  public:
40  const char* what() const throw() {return errstring;}
41  error(const char *fmt,...)
42  {
43  va_list args;
44  va_start(args, fmt);
45  vsprintf(errstring,fmt,args);
46  va_end(args);
47  abort_if_debug();
48  }
49  error() {errstring[0]='\0'; abort_if_debug();}
50  error(const error& e) {strncpy(errstring,e.errstring,200);}
51  };
52 }
53 #endif
EcoLab exception class.
Definition: error.h:25
_OPENMP
Definition: accessor.h:16