[C++-sig] RuntimeError: unidentifiable C++ exception
Qun Cao
quncao at gmail.com
Thu Aug 31 02:13:29 CEST 2006
>
> >* Hi Roman,
> *>* What do you mean by "the code generated by Py++ just works"? Do you mean
> *>* you created a class
> *>* MyClass {
> *>* public:
> *>* MyClass(char const*) ;
> *>* }
> *>* and you had successfully initialized it in Python? I tried a similar
> *>* example class and had no problem with it.
> *
> That what you described :-).
>
> >* The real problem I had was with this specific class NiString in Gamebryo
> *>* game engine, is it possible that something
> *>* going on inside Gamebryo might cause the problem? Or the game engine is
> *>* irrelevant to this problem?
> *
> I think that NiString is relevant. Take a look on this FAQ:
> http://www.boost.org/libs/python/doc/v2/faq.html#custom_string
>
> Hi Roman,
Thanks for you suggestions.
I looked into the custom_string code, it is a nice example but different
with my problem. I don't want python automatically convert my NiFixedString
to python string, all I want is a way to use the constructor of
NiFixedString class to create a python object.
a = NiFixedString("test")
Theoretically this is no different than wrapping any other class with a
constructor that takes a string/char const*, and this code should do it,
right?
BOOST_PYTHON_MODULE(NiStringTest)
{
class_<NiFixedString,boost::noncopyable>("pNiFixedString", init<char
const*>());
}
Btw, NiFixedString encapsulates a memory efficient implementation of
reference-counted ASCII strings, here is the header file, is there any thing
that potentially cause the exception? Also, from my understanding, PY++
simplifies the process of generating the wrapper code, could adopting PY++
possibly help with this problem?
#ifndef NIFIXEDSTRINGTABLE_H
#define NIFIXEDSTRINGTABLE_H
#include "NiRTLib.h"
#include "NiGlobalStringTable.h"
#include "NiPath.h"
class NIMAIN_ENTRY NiFixedString : public NiMemObject
{
public:
NiFixedString();
NiFixedString(const char* pcString);
NiFixedString(const NiFixedString& kString);
~NiFixedString();
operator const char*() const;
bool Exists() const;
NiFixedString& operator=(const NiFixedString& kString);
NiFixedString& operator=(const char* pcString);
size_t GetLength() const;
unsigned int GetRefCount() const;
bool Equals(const char* pcStr) const;
bool EqualsNoCase(const char* pcStr) const;
bool Contains(const char* pcStr) const;
bool ContainsNoCase(const char* pcStr) const;
friend bool operator==(const NiFixedString& s1, const NiFixedString&
s2);
friend bool operator!=(const NiFixedString& s1, const NiFixedString&
s2);
friend bool operator==(const NiFixedString& s1, const char* s2);
friend bool operator!=(const NiFixedString& s1, const char* s2);
friend bool operator==(const char* s1, const NiFixedString& s2);
friend bool operator!=(const char* s1, const NiFixedString& s2);
// Begin Emergent internal use only
// End Emergent internal use only
protected:
NiGlobalStringTable::GlobalStringHandle m_kHandle;
};
NIMAIN_ENTRY void NiStandardizeFilePath(NiFixedString& kString);
#include "NiFixedString.inl"
#endif
Excerpt from NifixedString.inl
inline NiFixedString::NiFixedString(const char* pcString)
{
if (pcString == NULL)
{
m_kHandle = NiGlobalStringTable::NULL_STRING;
}
else
{
m_kHandle = NiGlobalStringTable::AddString(pcString);
}
}
>* And still, what the "unidentifiable C++ exception" is really saying?
> *
> Boost.Python has next code:
>
> try{
> run you C++ code
> }
> catch( registered exceptions ){
> convert them to Python exception
> }
> catch( ... ){
> throw Python RuntimeError( "unidentifiable C++ exception" )
> }
>
> So or you forgot to register your exception or ... something really
> bad happened.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20060830/a5a68249/attachment.htm>
More information about the Cplusplus-sig
mailing list