source: issm/trunk-jpl/src/c/shared/Exceptions/exceptions.h@ 15100

Last change on this file since 15100 was 15100, checked in by Eric.Larour, 12 years ago

CHG: changed the names of _printString_ and _pprintString_
to _printf_ and _printf0_

File size: 2.7 KB
Line 
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
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
18using 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/*macros: */
27/* _assert_ {{{*/
28/*Assertion macro: do nothing if macro _ISSM_DEBUG_ undefined*/
29#ifdef _ISSM_DEBUG_
30#define _assert_(statement)\
31 if (!(statement)) _error_("Assertion \""<<#statement<<"\" failed, please report bug to "<<PACKAGE_BUGREPORT)
32#else
33#define _assert_(ignore)\
34 ((void) 0)
35#endif
36/*}}}*/
37/* _error_ {{{*/
38/*new Error exception macro*/
39#ifdef _INTEL_WIN_
40#define _error_(StreamArgs)\
41 do{std::ostringstream aLoNgAnDwEiRdLoCaLnAmeFoRtHiSmAcRoOnLy; \
42 aLoNgAnDwEiRdLoCaLnAmeFoRtHiSmAcRoOnLy << StreamArgs << std::ends; \
43 throw ErrorException(aLoNgAnDwEiRdLoCaLnAmeFoRtHiSmAcRoOnLy.str());}while(0)
44#else
45#define _error_(StreamArgs)\
46 do{std::ostringstream aLoNgAnDwEiRdLoCaLnAmeFoRtHiSmAcRoOnLy; \
47 aLoNgAnDwEiRdLoCaLnAmeFoRtHiSmAcRoOnLy << StreamArgs << std::ends; \
48 throw ErrorException(__FILE__,__func__,__LINE__,aLoNgAnDwEiRdLoCaLnAmeFoRtHiSmAcRoOnLy.str());}while(0)
49#endif
50/*}}}*/
51/* ExceptionTrapBegin/ExceptionTrapEnd {{{*/
52
53/*The following macros hide the error exception handling in a matlab module. Just put
54 * ExceptionTrapBegin(); and ExceptionTrapEnd(); at the beginning and end of a module, and c++ exceptions
55 * will be trapped. Really nifty!*/
56
57#define ExceptionTrapBegin(); \
58 try{
59
60#define ExceptionTrapEnd(); }\
61 catch(ErrorException &exception){\
62 exception.Report();\
63 return 0;\
64 }\
65 catch (exception& e) {\
66 _printf_("Standard exception: " << e.what() << "\n" << "\n");\
67 return 0;\
68 }\
69 catch(...){\
70 _printf_("An unexpected error occurred \n" << "\n");\
71 return 0;\
72 }
73/*}}}*/
74
75/*ISSM exception class: */
76class ErrorException: public exception { /*{{{*/
77
78 string what_str;
79 string function_name;
80 string file_name;
81 int file_line;
82
83 public:
84 ErrorException(const string &what_arg); //for windows
85 ErrorException(const string& what_file,const string& what_function,int what_line,const string& what_arg);//UNIX
86 ~ErrorException() throw();
87 virtual const char *what() const throw();
88 void Report() const;
89 const char* MatlabReport() const;
90 const char* PythonReport() const;
91
92};
93/*}}}*/
94
95char* exprintf(const char* format,...);
96
97#endif
Note: See TracBrowser for help on using the repository browser.