1
我有了這個代碼snnipet(整個程序編譯和鏈接正確):Python異常文本(boost庫)
...
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);
...
}
該程序試圖執行有語法錯誤的文件,所以拋出異常。當程序試圖讓錯誤信息崩潰時...
該代碼適用於運行時錯誤,但以某種方式崩潰的語法錯誤。
我怎樣才能得到這種錯誤的錯誤字符串?
預先感謝
嗯... pvalue不是NULL,ptraceback是NULL(由於它是語法錯誤,並且沒有堆棧幀,所以這很有意義) – jab 2011-02-17 09:18:14