3
0
mirror of https://github.com/triqs/dft_tools synced 2025-01-26 12:31:49 +01:00

exceptions handling : slight improve

- separate the stack trace from the error message for better python
  handling
- separate triqs::excption from triqs::runtime_error
This commit is contained in:
Olivier Parcollet 2014-04-23 18:47:17 +02:00
parent a0bfead2c6
commit 384c05188c

View File

@ -30,19 +30,26 @@
namespace triqs { namespace triqs {
class runtime_error : public std::exception { class exception : public std::exception {
std::string acc; std::string acc, trace;
public: public:
runtime_error() throw() :std::exception() {} exception() throw() :std::exception() { trace = utility::stack_trace();}
virtual ~runtime_error() throw() {} virtual ~exception() throw() {}
template<typename T> runtime_error & operator <<( T const & x) { std::stringstream f; f<<acc<<x; acc = f.str(); return *this;} template<typename T> exception & operator <<( T const & x) { std::stringstream f; f<<acc<<x; acc = f.str(); return *this;}
runtime_error & operator <<( const char * mess ) { (*this) << std::string(mess); return *this;}// to limit code size exception & operator <<( const char * mess ) { (*this) << std::string(mess); return *this;}// to limit code size
virtual const char* what() const throw() { return acc.c_str();} virtual const char* what() const throw() { return acc.c_str();}
}; };
class runtime_error : public exception {
public:
runtime_error() throw() : exception() {}
virtual ~runtime_error() throw() {}
template<typename T> runtime_error & operator <<( T && x) { exception::operator<<(x); return *this; }
};
} }
#define TRIQS_ERROR(CLASS,NAME) throw CLASS()<<" Triqs "<<NAME<<" at "<<__FILE__<< " : "<<__LINE__<<"\n\n Trace is :\n\n"<<triqs::utility::stack_trace()<<"\n" #define TRIQS_ERROR(CLASS,NAME) throw CLASS()<<" Triqs "<<NAME<<" at "<<__FILE__<< " : "<<__LINE__<<"\n\n"
#define TRIQS_RUNTIME_ERROR TRIQS_ERROR(triqs::runtime_error,"runtime error") #define TRIQS_RUNTIME_ERROR TRIQS_ERROR(triqs::runtime_error,"runtime error")
#endif #endif