Go to the documentation of this file.00001 #include "FWCore/PythonParameterSet/src/PythonWrapper.h"
00002 #include "FWCore/Utilities/interface/Exception.h"
00003
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
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
00033 throw cms::Exception(iType)
00034 << "python encountered the error: "
00035
00036 << PyString_AsString(stringExc.ptr()) << "\n"
00037
00038 << PyString_AsString(stringVal.ptr()) << "\n";
00039 } else {
00040 throw cms::Exception(iType)<<" unknown python problem occurred.\n";
00041 }
00042 }
00043
00044 }
00045
00046