mirror of
https://github.com/triqs/dft_tools
synced 2024-12-24 13:23:37 +01:00
Add date+time in C++ exceptions in wrapper
- the wrapper will now add date and time at the boundary between C++ and Python. - using C lib, not C++ (lack of support of C++ chrono functions in gcc).
This commit is contained in:
parent
e3e652f556
commit
0c64c2a010
@ -6,21 +6,28 @@
|
||||
#include <vector>
|
||||
#include <triqs/utility/exceptions.hpp>
|
||||
#include "./pyref.hpp"
|
||||
#include <time.h>
|
||||
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-writable-strings"
|
||||
#pragma GCC diagnostic ignored "-Wwrite-strings"
|
||||
|
||||
inline char *get_current_time() { // helper function to print the time in the CATCH_AND_RETURN macro
|
||||
time_t rawtime;
|
||||
time(&rawtime);
|
||||
return ctime(&rawtime);
|
||||
}
|
||||
|
||||
// I can use the trace in triqs::exception
|
||||
#define CATCH_AND_RETURN(MESS,RET)\
|
||||
catch(triqs::keyboard_interrupt const & e) {\
|
||||
PyErr_SetString(PyExc_KeyboardInterrupt, e.what());\
|
||||
return RET; }\
|
||||
catch(triqs::exception const & e) {\
|
||||
auto err = std::string("Error " MESS "\nC++ error was : \n") + e.what();\
|
||||
auto err = std::string("Error occurred at ") + get_current_time() + "\nError " + MESS + "\nC++ error was : \n" + e.what();\
|
||||
PyErr_SetString(PyExc_RuntimeError, err.c_str());\
|
||||
return RET; }\
|
||||
catch(std::exception const & e) {\
|
||||
auto err = std::string("Error " MESS "\nC++ error was : \n") + e.what();\
|
||||
auto err = std::string("Error occurred at ") + get_current_time() + "\nError " + MESS + "\nC++ error was : \n" + e.what();\
|
||||
PyErr_SetString(PyExc_RuntimeError, err.c_str());\
|
||||
return RET; }\
|
||||
catch(...) { PyErr_SetString(PyExc_RuntimeError,"Unknown error " MESS ); return RET; }\
|
||||
|
@ -31,13 +31,14 @@
|
||||
namespace triqs {
|
||||
|
||||
class exception : public std::exception {
|
||||
std::string acc, trace;
|
||||
std::string acc, _trace;
|
||||
public:
|
||||
exception() throw() :std::exception() { trace = utility::stack_trace();}
|
||||
exception() throw() :std::exception() { _trace = utility::stack_trace();}
|
||||
virtual ~exception() throw() {}
|
||||
template<typename T> exception & operator <<( T const & x) { std::stringstream f; f<<acc<<x; acc = f.str(); return *this;}
|
||||
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* trace() const throw() { return _trace.c_str();}
|
||||
};
|
||||
|
||||
class runtime_error : public exception {
|
||||
|
Loading…
Reference in New Issue
Block a user