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

Last change on this file since 26976 was 26976, checked in by Mathieu Morlighem, 3 years ago

CHG: removing dependencies between Exceptions and ISSM

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