From 0c64c2a01048611d95aa9cbb558b2fada3320cd9 Mon Sep 17 00:00:00 2001 From: Olivier Parcollet Date: Wed, 23 Jul 2014 15:47:19 +0200 Subject: [PATCH] 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). --- triqs/python_tools/wrapper_tools.hpp | 11 +++++++++-- triqs/utility/exceptions.hpp | 5 +++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/triqs/python_tools/wrapper_tools.hpp b/triqs/python_tools/wrapper_tools.hpp index f504420d..aafd71ef 100644 --- a/triqs/python_tools/wrapper_tools.hpp +++ b/triqs/python_tools/wrapper_tools.hpp @@ -6,21 +6,28 @@ #include #include #include "./pyref.hpp" +#include #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; }\ diff --git a/triqs/utility/exceptions.hpp b/triqs/utility/exceptions.hpp index c117943c..4c5f979a 100644 --- a/triqs/utility/exceptions.hpp +++ b/triqs/utility/exceptions.hpp @@ -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 exception & operator <<( T const & x) { std::stringstream f; f<