Changeset 1646 for XIOS/dev/dev_trunk_omp/src/exception.hpp
- Timestamp:
- 01/31/19 12:12:52 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/dev/dev_trunk_omp/src/exception.hpp
r792 r1646 5 5 #include "xios_spl.hpp" 6 6 #include "object.hpp" 7 #include <iomanip> 8 #include <stdexcept> 7 9 8 10 namespace xios 9 11 { 10 12 /// ////////////////////// Déclarations ////////////////////// /// 13 11 14 class CException 12 15 : private CObject, public StdOStringStream … … 33 36 virtual void fromString(const StdString & str); 34 37 38 struct StackInfo 39 { 40 StdString file; 41 StdString function; 42 int line; 43 StdString info; 44 }; 45 46 std::list<StackInfo> stack; 47 35 48 private : 36 49 37 50 /// Propriétés /// 38 51 bool desc_rethrow; // throw destructor 52 StdOStringStream stream; 39 53 40 54 }; // CException … … 43 57 /// //////////////////////////// Macros //////////////////////////// /// 44 58 59 #define FILE_NAME (std::strrchr("/" __FILE__, '/') + 1) 60 61 #define FUNCTION_NAME (StdString(BOOST_CURRENT_FUNCTION).length() > 100 ? \ 62 StdString(BOOST_CURRENT_FUNCTION).substr(0,100).append("...)") : BOOST_CURRENT_FUNCTION) 63 45 64 #define INFO(x) \ 46 "In file \ '" __FILE__ "\',line " << __LINE__ << " -> " x << std::endl;65 "In file \""<< FILE_NAME <<"\", function \"" << BOOST_CURRENT_FUNCTION <<"\", line " << __LINE__ << " -> " x << std::endl; 47 66 48 67 #ifdef __XIOS_DEBUG … … 52 71 #endif 53 72 54 #define ERROR(id, x) xios::CException(id).getStream() << INFO(x) 73 #define ERROR(id, x) \ 74 { \ 75 xios::CException exc(id); \ 76 exc.getStream() << INFO(x); \ 77 error << exc.getMessage() << std::endl; \ 78 throw exc; \ 79 } 80 81 #ifdef __XIOS_EXCEPTION 82 #define TRY \ 83 { \ 84 int funcFirstLine = __LINE__; \ 85 try 86 #define CATCH \ 87 catch(CException& e) \ 88 { \ 89 CException::StackInfo stk; \ 90 stk.file = FILE_NAME; \ 91 stk.function = FUNCTION_NAME; \ 92 stk.line = funcFirstLine; \ 93 e.stack.push_back(stk); \ 94 if (CXios::xiosStack) \ 95 throw; \ 96 else \ 97 throw 0; \ 98 } \ 99 } 100 #define CATCH_DUMP_ATTR \ 101 catch(CException& e) \ 102 { \ 103 CException::StackInfo stk; \ 104 stk.info.append(StdString("Object id=\"" + this->getId()) + "\" object type=\"" + this->getName() + "\"\n"); \ 105 stk.info.append("*** XIOS attributes as defined in XML file(s) or via Fortran interface:\n"); \ 106 stk.info.append("[" + this->dumpXiosAttributes() + "]\n"); \ 107 stk.info.append("*** Additional information:\n"); \ 108 stk.info.append("[" + this->dumpClassAttributes() + "]\n"); \ 109 stk.file = FILE_NAME; \ 110 stk.function = FUNCTION_NAME; \ 111 stk.line = funcFirstLine; \ 112 e.stack.push_back(stk); \ 113 if (CXios::xiosStack) \ 114 throw; \ 115 else \ 116 throw 0; \ 117 } \ 118 } 119 #define CATCH_DUMP_STACK \ 120 catch(CException& e) \ 121 { \ 122 CException::StackInfo stk; \ 123 int i = 1; \ 124 stk.file = FILE_NAME; \ 125 stk.function = FUNCTION_NAME; \ 126 stk.line = funcFirstLine; \ 127 e.stack.push_back(stk); \ 128 for (auto itr = e.stack.crbegin(); itr!=e.stack.crend(); ++itr) \ 129 { \ 130 error << "("<< i <<") **************** "; \ 131 error << itr->function << std::endl; \ 132 error << itr->info << std::endl; \ 133 ++i; \ 134 } \ 135 error << left << " "; \ 136 error << left << std::setw(40) << "File " ; \ 137 error << left << std::setw(106) << "Function " ; \ 138 error << std::setw(5) << "Line " << std::endl; \ 139 i = e.stack.size(); \ 140 for (auto itr = e.stack.begin(); itr!=e.stack.end(); itr++) \ 141 { \ 142 StdOStringStream tmp; \ 143 tmp << "("<< i <<")"; \ 144 error << left << std::setw(6) << tmp.str(); \ 145 error << left << std::setw(40) << itr->file; \ 146 error << left << std::setw(106) << itr->function; \ 147 error << left << std::setw(5) << itr->line << std::endl; \ 148 --i; \ 149 } \ 150 throw; \ 151 } \ 152 } 153 #else 154 #define TRY 155 #define CATCH 156 #define CATCH_DUMP_ATTR 157 #define CATCH_DUMP_STACK 158 #endif 55 159 56 160 #endif // __XIOS_CException__ 161
Note: See TracChangeset
for help on using the changeset viewer.