CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PythonWrapper.cc
Go to the documentation of this file.
3 //#include <iostream>
4 namespace edm {
5 
6 void pythonToCppException(const std::string& iType)
7  {
8  using namespace boost::python;
9  PyObject *exc=NULL, *val=NULL, *trace=NULL;
10  PyErr_Fetch(&exc,&val,&trace);
11  PyErr_NormalizeException(&exc,&val,&trace);
12  handle<> hExc(allow_null(exc));
13  handle<> hVal(allow_null(val));
14  handle<> hTrace(allow_null(trace));
15 
16  if(hTrace) {
17  object oTrace(hTrace);
18  handle<> hStringTr(PyObject_Str(oTrace.ptr()));
19  object stringTr(hStringTr);
20 //std::cout << "PR TR " << stringTr << " DONE "<< std::endl;
21  }
22 
23  if(hVal && hExc) {
24  object oExc(hExc);
25  object oVal(hVal);
26  handle<> hStringVal(PyObject_Str(oVal.ptr()));
27  object stringVal( hStringVal );
28 
29  handle<> hStringExc(PyObject_Str(oExc.ptr()));
30  object stringExc( hStringExc);
31 
32  //PyErr_Print();
33  throw cms::Exception(iType)
34  << "python encountered the error: "
35  // include python exception type
36  << PyString_AsString(stringExc.ptr()) << "\n"
37  // message in the python exception
38  << PyString_AsString(stringVal.ptr()) << "\n";
39  } else {
40  throw cms::Exception(iType)<<" unknown python problem occurred.\n";
41  }
42 }
43 
44 }
45 
46 
void pythonToCppException(const std::string &iType)
Definition: PythonWrapper.cc:6
#define NULL
Definition: scimark2.h:8
double trace(const ROOT::Math::SMatrix< double, N, N > &matrix)