Improve reporting of Python exceptions

This commit is contained in:
wmayer
2013-05-04 14:23:53 +02:00
parent 2bbe465229
commit 946bd02df4
12 changed files with 58 additions and 56 deletions

View File

@@ -48,7 +48,7 @@ public:
Exception &operator=(const Exception &inst);
virtual const char* what(void) const throw();
void ReportException (void) const;
virtual void ReportException (void) const;
inline void setMessage(const char * sMessage);
inline void setMessage(const std::string& sMessage);

View File

@@ -71,9 +71,18 @@ PyException::PyException(void)
_stackTrace = PP_last_error_trace; /* exception traceback text */
}
PyException::~PyException() throw()
{
PyGILStateLocker locker;
PyErr_Clear(); // must be called to keep Python interpreter in a valid state (Werner)
}
void PyException::ReportException (void) const
{
Base::Console().Error("%s%s: %s\n",
_stackTrace.c_str(), _errorType.c_str(), what());
}
// ---------------------------------------------------------

View File

@@ -54,11 +54,12 @@ class BaseExport PyException : public Exception
public:
/// constructor does the whole job
PyException(void);
~PyException() throw() {}
~PyException() throw();
/// this function returns the stack trace
const std::string &getStackTrace(void) const {return _stackTrace;}
const std::string &getErrorType(void) const {return _errorType;}
void ReportException (void) const;
protected:
std::string _stackTrace;