나는이 코드 snnipet있어 (전체 프로그램 컴파일 및 링크 정확하게) :파이썬 예외 구문 오류 텍스트 (부스트 라이브러리)
...
try
{
boost::python::exec_file(
"myscript.py", // this file contains a syntax error
my_main_namespace,
my_local_namespace
);
return true;
}
catch(const boost::python::error_already_set &)
{
PyObject *ptype, *pvalue, *ptraceback;
PyErr_Fetch(&ptype, &pvalue, &ptraceback);
// the next line crashes on syntax error
std::string error = boost::python::extract<std::string>(pvalue);
...
}
프로그램에 구문 오류가 있습니다 실행하려고 파일, 그래서 예외가 던져진다. 프로그램이 오류 메시지를 가져 오려고 할 때 ...
이 코드는 런타임 오류와 잘 맞지만 구문 오류로 인해 충돌합니다.
어떻게 이런 종류의 오류가있는 오류 문자열을 얻을 수 있습니까? documentation of PyErr_Fetch에서 미리
흠 ... pvalue가 NULL이 아니고 ptraceback이 NULL입니다 (구문 오류로 인해 의미가 있으며 스택 프레임이 없습니다) – jab
솔루션이 모든 오류에 대해 잘 작동하는 것 같습니다! – jab