# HG changeset patch # User Mike Miller # Date 1491152802 25200 # Node ID d36f06f07082e6f086a6e8cfc888c419261d6fce # Parent f777dca5836119484c1c1a23e6614d6897a28ecc Minor code reorganization to previous commit * exceptions.cc (pytave::fetch_exception_message): Reorganize code to keep declaration with use, other cleanups. diff -r f777dca58361 -r d36f06f07082 exceptions.cc --- a/exceptions.cc Sun Apr 02 05:58:35 2017 +0530 +++ b/exceptions.cc Sun Apr 02 10:06:42 2017 -0700 @@ -50,18 +50,17 @@ std::string fetch_exception_message (void) { PyObject *ptype, *pvalue, *ptraceback; - PyObject *formatted_list, *pargs; - PyErr_Fetch (&ptype, &pvalue, &ptraceback); PyErr_NormalizeException (&ptype, &pvalue, &ptraceback); - std::string message; - pargs = PyTuple_New (2); - PyTuple_SetItem (pargs, 0, ptype); - PyTuple_SetItem (pargs, 1, pvalue); - formatted_list = py_call_function \ - ("traceback.format_exception_only", pargs); - Py_DECREF (pargs); + PyObject *args = PyTuple_New (2); + PyTuple_SetItem (args, 0, ptype); + PyTuple_SetItem (args, 1, pvalue); + PyObject *formatted_list = py_call_function + ("traceback.format_exception_only", args); + Py_DECREF (args); + + std::string message; if (formatted_list && PyList_Check (formatted_list)) { @@ -75,8 +74,9 @@ { PyErr_Restore (ptype, pvalue, ptraceback); PyErr_Print (); - message = std::string ("exceptions.cc (pytave::fetch_exception_message): Cannot call 'format_exceptions_only' for the traceback"); + message = "exceptions.cc (pytave::fetch_exception_message): cannot call 'format_exceptions_only' for the traceback"; } + return message; } }