Mercurial > pytave
changeset 233:0deddd1b0526
Eliminate extra newlines in Python error formatting
* exceptions.cc (pytave::fetch_exception_message): Join the list of strings
without extra newlines and strip trailing newline. Clean up declarations.
author | Mike Miller <mtmiller@octave.org> |
---|---|
date | Wed, 20 Jul 2016 13:32:29 -0700 |
parents | c02f0a4c92e7 |
children | 237b71aaf6e7 |
files | exceptions.cc |
diffstat | 1 files changed, 9 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/exceptions.cc Wed Jul 20 13:15:32 2016 -0700 +++ b/exceptions.cc Wed Jul 20 13:32:29 2016 -0700 @@ -49,18 +49,21 @@ std::string fetch_exception_message (void) { using namespace boost::python; + PyObject *ptype, *pvalue, *ptraceback; PyErr_Fetch (&ptype, &pvalue, &ptraceback); std::string message; try { - object formatted_list, formatted; - handle<> htype (ptype), hval (allow_null (pvalue)); - object traceback (import ("traceback")); - object format_exception_only (traceback.attr ("format_exception_only")); - formatted_list = format_exception_only (htype, hval); - formatted = str ("\n").join (formatted_list); + handle<> htype (ptype); + handle<> hval (allow_null (pvalue)); + + object traceback = import ("traceback"); + object format_exception_only = traceback.attr ("format_exception_only"); + + object formatted_list = format_exception_only (htype, hval); + object formatted = str ("").join (formatted_list).strip (); message = extract<std::string> (formatted); } catch (error_already_set const &)