~christopher-hunt08/maus/maus_integrated_kalman

« back to all changes in this revision

Viewing changes to src/common_cpp/Utils/CppErrorHandler.cc

  • Committer: Durga Rajaram
  • Date: 2014-07-16 15:13:05 UTC
  • mfrom: (659.1.92 cand)
  • Revision ID: durga@fnal.gov-20140716151305-q27rv1y9p03v9lks
Tags: MAUS-v0.9, MAUS-v0.9.0
MAUS-v0.9.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
 
45
45
Json::Value CppErrorHandler::HandleStdExc
46
46
                (Json::Value val, std::exception& exc, std::string class_name) {
47
 
  return getInstance()->ExceptionToPython((&exc)->what(), val, class_name);
 
47
  Json::Value out = getInstance()->ExceptionToPython((&exc)->what(), val, class_name);
 
48
  return out;
48
49
}
49
50
 
50
51
void CppErrorHandler::HandleExceptionNoJson(Exception exc, std::string class_name) {
51
 
  HandleException(Json::Value(), exc, class_name);
 
52
  Json::Value json = Json::Value();
 
53
  HandleException(json, exc, class_name);
52
54
}
53
55
 
54
56
void CppErrorHandler::HandleStdExcNoJson
55
57
                                 (std::exception& exc, std::string class_name) {
56
 
  HandleStdExc(Json::Value(), exc, class_name);
 
58
  Json::Value json = Json::Value();
 
59
  HandleStdExc(json, exc, class_name);
57
60
}
58
61
 
59
62
Json::Value CppErrorHandler::ExceptionToPython
68
71
  PyErr_Clear();  // clear any existing exceptions
69
72
  Json::FastWriter writer;
70
73
  std::string json_in_cpp = writer.write(json_value);
71
 
  char sss[4] = {'s', 's', 's', '\0'};  // gotta love C (dodge compiler warning)
 
74
  char* sss = const_cast<char*>("sss");  // gotta love C (dodge compiler warning)
72
75
  PyObject* error_handler_function = GetPyErrorHandler();
73
76
  PyObject* json_out_py = PyObject_CallFunction  // call the Python ErrorHandler
74
 
                (error_handler_function, &sss[0],
 
77
                (error_handler_function, sss,
75
78
                 json_in_cpp.c_str(), class_name.c_str(), what.c_str());
76
79
  Py_DECREF(error_handler_function);
77
80
  const char* json_str;
78
81
  if (!json_out_py) {  // python ErrorHandler was set to raise the error
79
 
    // Squeak::mout(Squeak::error) << "ERROR: Failed to handle error:" << std::endl;
80
 
    // PyErr_Print();
 
82
    Squeak::mout(Squeak::error) << "ERROR: Failed to handle error:" << std::endl;
 
83
    PyErr_Print();
81
84
    throw std::exception();
82
85
  }
83
86
  int ok = PyArg_Parse(json_out_py, "s", &json_str);  // convert to string