CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/FWCore/PythonParameterSet/src/PythonWrapper.cc

Go to the documentation of this file.
00001 #include "FWCore/PythonParameterSet/src/PythonWrapper.h"
00002 #include "FWCore/Utilities/interface/Exception.h"
00003 //#include <iostream>
00004 namespace edm {
00005 
00006 void pythonToCppException(const std::string& iType)
00007  {
00008   using namespace boost::python;
00009   PyObject *exc=NULL, *val=NULL, *trace=NULL;
00010   PyErr_Fetch(&exc,&val,&trace);
00011   PyErr_NormalizeException(&exc,&val,&trace);
00012   handle<> hExc(allow_null(exc));
00013   handle<> hVal(allow_null(val));
00014   handle<> hTrace(allow_null(trace));
00015  
00016   if(hTrace) {
00017     object oTrace(hTrace);
00018     handle<> hStringTr(PyObject_Str(oTrace.ptr()));
00019     object stringTr(hStringTr);
00020 //std::cout << "PR TR " << stringTr <<  " DONE "<<  std::endl;
00021   }
00022 
00023   if(hVal && hExc) {
00024     object oExc(hExc);
00025     object oVal(hVal);
00026     handle<> hStringVal(PyObject_Str(oVal.ptr()));
00027     object stringVal( hStringVal );
00028 
00029     handle<> hStringExc(PyObject_Str(oExc.ptr()));
00030     object stringExc( hStringExc);
00031 
00032     //PyErr_Print();
00033     throw cms::Exception(iType)
00034       << "python encountered the error: "
00035       // include python exception type
00036       << PyString_AsString(stringExc.ptr()) << "\n"
00037       // message in the python exception
00038       << PyString_AsString(stringVal.ptr()) << "\n"; 
00039   } else {
00040     throw cms::Exception(iType)<<" unknown python problem occurred.\n";
00041   }
00042 }
00043 
00044 }
00045 
00046