• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

MLAPI_Error.h

Go to the documentation of this file.
00001 /* ******************************************************************** */
00002 /* See the file COPYRIGHT for a complete copyright notice, contact      */
00003 /* person and disclaimer.                                               */        
00004 /* ******************************************************************** */
00005 #ifndef MLAPI_ERROR_H
00006 #define MLAPI_ERROR_H
00007 
00008 #include <string>
00009 #include <iostream>
00010 
00011 namespace MLAPI {
00012 
00013 typedef struct StackEntry {
00014   int line;
00015   std::string FileName;
00016   std::string FuncName;
00017 } Entry;
00018 
00019 #ifdef MLAPI_CHECK
00020 #ifdef HAVE_ML_CFUNC
00021 #define StackPush() \
00022   StackPush_(__PRETTY_FUNCTION__, __FILE__, __LINE__)
00023 #else
00024 #define StackPush() \
00025   StackPush_("function not available", __FILE__, __LINE__)
00026 #endif
00027 #else
00028 #define StackPush()
00029 #endif
00030 
00031 #ifdef MLAPI_CHECK
00032 void StackPush_(std::string FuncName, std::string FileName, int line);
00033 
00034 void StackPop();
00035 
00036 void StackPrint();
00037 #else
00038 inline void StackPop() {}
00039 inline void StackPrint() {std::cout << "Compile with -DMLAPI_CHECK to get the function stack" << std::endl;}
00040 #endif
00041 
00042 
00043 } // namespace MLAPI
00044 
00045 #ifndef ML_THROW
00046 #ifdef HAVE_ML_CFUNC
00047 // some old compilers do not have __func__
00048 #define ML_THROW(str,val) { \
00049   std::cerr << "ERROR: In " << __PRETTY_FUNCTION__ << "()" << endl; \
00050   std::cerr << "ERROR: File " << __FILE__ << ", line " << __LINE__ << endl; \
00051   std::cerr << "ERROR: " << str << endl; \
00052   StackPrint(); \
00053   throw(val); \
00054   }
00055 #else
00056 #define ML_THROW(str,val) { \
00057   std::cerr << "ERROR: File " << __FILE__ << ", line " << __LINE__ << endl; \
00058   std::cerr << "ERROR: " << str << endl; \
00059   StackPrint(); \
00060   throw(val); \
00061   }
00062 #endif // HAVE_ML_CFUNC
00063 #endif // ndef ML_THROW
00064 
00065 #endif // MLAPI_ERROR_H