[~] add cast exception to str

[~] add contructor for DiaException

git-svn-id: https://pykd.svn.codeplex.com/svn@69806 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\EreTIk_cp 2011-09-16 19:23:25 +00:00 committed by Mikhail I. Izmestev
parent 586995de47
commit 479f2745f6
4 changed files with 22 additions and 5 deletions

View File

@ -27,6 +27,10 @@ public:
baseExceptTypeObject = p; baseExceptTypeObject = p;
} }
std::string print() {
return what();
}
private: private:
static PyObject *baseExceptTypeObject; static PyObject *baseExceptTypeObject;
}; };

View File

@ -164,7 +164,8 @@ BOOST_PYTHON_MODULE( pykd )
dbgExceptionClass dbgExceptionClass
.def( python::init<std::string>( python::args("desc"), "constructor" ) ) .def( python::init<std::string>( python::args("desc"), "constructor" ) )
.def( "desc", &DbgException::getDesc, .def( "desc", &DbgException::getDesc,
"Get exception description" ); "Get exception description" )
.def( "__str__", &DbgException::print);
DbgException::setTypeObject( dbgExceptionClass.ptr() ); DbgException::setTypeObject( dbgExceptionClass.ptr() );
// DIA exceptions // DIA exceptions

View File

@ -14,13 +14,14 @@ namespace pyDia {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
PyObject *Exception::diaExceptTypeObject = NULL; PyObject *Exception::diaExceptTypeObject = NULL;
const std::string Exception::descPrefix("pyDia: ");
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
std::string Exception::makeFullDesc(const std::string &desc, HRESULT hres) std::string Exception::makeFullDesc(const std::string &desc, HRESULT hres)
{ {
std::strstream res; std::strstream res;
res << "pyDia: " << desc << " failed" << std::endl; res << descPrefix << desc << " failed" << std::endl;
res << "Return value is 0x" << std::hex << hres; res << "Return value is 0x" << std::hex << hres;
PCHAR errMessage = NULL; PCHAR errMessage = NULL;
@ -153,8 +154,11 @@ python::object Symbol::getChildByName(const std::string &_name)
if (FAILED(hres)) if (FAILED(hres))
throw Exception("Get count of children", hres); throw Exception("Get count of children", hres);
if (!count)
throw Exception(_name + " not found as children");
if (count != 1) if (count != 1)
throw Exception("Query unique child", S_FALSE); throw Exception(_name + " is not unique");
CComPtr< IDiaSymbol > child; CComPtr< IDiaSymbol > child;
hres = symbols->Item(0, &child); hres = symbols->Item(0, &child);
@ -210,7 +214,7 @@ python::object Symbol::getChildByIndex(ULONG _index)
throw Exception("Get count of children", hres); throw Exception("Get count of children", hres);
if (LONG(_index) >= count) if (LONG(_index) >= count)
throw Exception("Check child index", S_FALSE); throw Exception("Attempt to access non-existing element: index overflow");
CComPtr< IDiaSymbol > child; CComPtr< IDiaSymbol > child;
hres = symbols->Item(_index, &child); hres = symbols->Item(_index, &child);

View File

@ -15,6 +15,12 @@ public:
{ {
} }
Exception(const std::string &desc)
: DbgException(descPrefix + desc)
, m_hres(S_FALSE)
{
}
HRESULT getRes() const { HRESULT getRes() const {
return m_hres; return m_hres;
} }
@ -27,6 +33,8 @@ public:
private: private:
static const std::string descPrefix;
static PyObject *diaExceptTypeObject; static PyObject *diaExceptTypeObject;
static std::string makeFullDesc(const std::string &desc, HRESULT hres); static std::string makeFullDesc(const std::string &desc, HRESULT hres);
@ -67,7 +75,7 @@ protected:
void throwIfNull(const char *desc) void throwIfNull(const char *desc)
{ {
if (!m_symbol) if (!m_symbol)
throw Exception(desc, S_FALSE); throw Exception(std::string(desc) + " failed, object not preinitialized");
} }
Symbol(__inout CComPtr< IDiaSymbol > &_symbol) { Symbol(__inout CComPtr< IDiaSymbol > &_symbol) {