Ice Sheet System Model  4.18
Code documentation
exceptions.h
Go to the documentation of this file.
1 
9 #ifndef _MY_EXCEPTIONS_H_
10 #define _MY_EXCEPTIONS_H_
11 
12 #include <exception>
13 #include <string>
14 #include <iostream>
15 #include <sstream>
16 #include <iomanip>
17 
18 using namespace std;
19 
20 #ifdef HAVE_CONFIG_H
21  #include <config.h>
22 #else
23 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
24 #endif
25 
26 /*Only include forward declaration to save compile time*/
27 #include <iosfwd>
28 #include <sstream>
29 
30 /*macros: */
31 /* _assert_ {{{*/
32 /*Assertion macro: do nothing if macro _ISSM_DEBUG_ undefined*/
33 #ifdef _ISSM_DEBUG_
34 #define _assert_(statement)\
35  if (!(statement)) _error_("Assertion \""<<#statement<<"\" failed, please report bug to "<<PACKAGE_BUGREPORT)
36 #else
37 #define _assert_(ignore)\
38  ((void) 0)
39 #endif
40 /*}}}*/
41 /* _error_ {{{*/
42 /*new Error exception macro*/
43 #ifdef _INTEL_WIN_
44 #define _error_(StreamArgs)\
45  do{std::ostringstream aLoNgAnDwEiRdLoCaLnAmeFoRtHiSmAcRoOnLy; \
46  aLoNgAnDwEiRdLoCaLnAmeFoRtHiSmAcRoOnLy << StreamArgs << std::ends; \
47  throw ErrorException(aLoNgAnDwEiRdLoCaLnAmeFoRtHiSmAcRoOnLy.str());}while(0)
48 #else
49 #define _error_(StreamArgs)\
50  do{std::ostringstream aLoNgAnDwEiRdLoCaLnAmeFoRtHiSmAcRoOnLy; \
51  aLoNgAnDwEiRdLoCaLnAmeFoRtHiSmAcRoOnLy << StreamArgs << std::ends; \
52  throw ErrorException(__FILE__,__func__,__LINE__,aLoNgAnDwEiRdLoCaLnAmeFoRtHiSmAcRoOnLy.str());}while(0)
53 #endif
54 /*}}}*/
55 /* ExceptionTrapBegin/ExceptionTrapEnd {{{*/
56 
57 /*The following macros hide the error exception handling in a matlab module. Just put
58  * ExceptionTrapBegin(); and ExceptionTrapEnd(); at the beginning and end of a module, and c++ exceptions
59  * will be trapped. Really nifty!*/
60 
61 #define ExceptionTrapBegin(); \
62  try{
63 
64 #define ExceptionTrapEnd(); }\
65  catch(ErrorException &exception){\
66  exception.Report();\
67  return 1;\
68  }\
69  catch(exception& e) {\
70  _printf_("Standard exception: " << e.what() << "\n\n");\
71  return 1;\
72  }\
73  catch(...){\
74  _printf_("An unexpected error occurred \n\n");\
75  return 1;\
76  }
77 /*}}}*/
78 
79 /*ISSM exception class: */
80 class ErrorException: public exception { /*{{{*/
81 
82  char* what_str;
84  char* file_name;
85  int file_line;
86 
87  public:
88  ErrorException(const string &what_arg); //for windows
89  ErrorException(const string &what_file,const string& what_function,int what_line,const string& what_arg);//UNIX
90  ~ErrorException() throw();
91  virtual const char *what() const throw();
92  void Report() const;
93  const char* WrapperReport() const;
94 
95 };
96 /*}}}*/
97 #endif
ErrorException::file_name
char * file_name
Definition: exceptions.h:84
ErrorException::function_name
char * function_name
Definition: exceptions.h:83
ErrorException
Definition: exceptions.h:80
ErrorException::what_str
char * what_str
Definition: exceptions.h:82
ErrorException::file_line
int file_line
Definition: exceptions.h:85