[1] | 1 | /*!\file exceptions.h
|
---|
| 2 | * \brief: two types of exceptions are handled for now. Errors, and
|
---|
| 3 | * warnings. Those exceptions are trapped provided the matlab modules
|
---|
| 4 | * are started using MODULEBOOT, and ended using MODULEEND. These are
|
---|
| 5 | * macros hiding try, catch statements. This header file defines our
|
---|
| 6 | * own exceptions
|
---|
| 7 | */
|
---|
| 8 |
|
---|
[14914] | 9 | #ifndef _MY_EXCEPTIONS_H_
|
---|
| 10 | #define _MY_EXCEPTIONS_H_
|
---|
[1] | 11 |
|
---|
| 12 | #include <exception>
|
---|
| 13 | #include <string>
|
---|
[14914] | 14 | #include <iostream>
|
---|
| 15 | #include <sstream>
|
---|
| 16 | #include <iomanip>
|
---|
| 17 |
|
---|
[1] | 18 | using namespace std;
|
---|
| 19 |
|
---|
[14914] | 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
|
---|
[13623] | 25 |
|
---|
[24477] | 26 | /*Only include forward declaration to save compile time*/
|
---|
| 27 | #include <iosfwd>
|
---|
| 28 | #include <sstream>
|
---|
| 29 |
|
---|
[14914] | 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();\
|
---|
[22634] | 67 | return 1;\
|
---|
[14914] | 68 | }\
|
---|
[17513] | 69 | catch(exception& e) {\
|
---|
[15104] | 70 | _printf_("Standard exception: " << e.what() << "\n\n");\
|
---|
[22634] | 71 | return 1;\
|
---|
[14914] | 72 | }\
|
---|
| 73 | catch(...){\
|
---|
[15104] | 74 | _printf_("An unexpected error occurred \n\n");\
|
---|
[22634] | 75 | return 1;\
|
---|
[14914] | 76 | }
|
---|
| 77 | /*}}}*/
|
---|
| 78 |
|
---|
| 79 | /*ISSM exception class: */
|
---|
| 80 | class ErrorException: public exception { /*{{{*/
|
---|
| 81 |
|
---|
[16155] | 82 | char* what_str;
|
---|
| 83 | char* function_name;
|
---|
| 84 | char* file_name;
|
---|
| 85 | int file_line;
|
---|
[1] | 86 |
|
---|
[12079] | 87 | public:
|
---|
[3329] | 88 | ErrorException(const string &what_arg); //for windows
|
---|
[16152] | 89 | ErrorException(const string &what_file,const string& what_function,int what_line,const string& what_arg);//UNIX
|
---|
[1] | 90 | ~ErrorException() throw();
|
---|
| 91 | virtual const char *what() const throw();
|
---|
[13363] | 92 | void Report() const;
|
---|
[19701] | 93 | const char* WrapperReport() const;
|
---|
[1] | 94 |
|
---|
| 95 | };
|
---|
[14914] | 96 | /*}}}*/
|
---|
[1] | 97 | #endif
|
---|