[C++-sig] Exception Translation

jesus garcia jesus24b at gmail.com
Wed Jun 7 18:25:29 CEST 2006


I like export the follow simple program

#define REPORT_ERROR(nerr,ErrorMsg) throw error(nerr,ErrorMsg)

where error is a class

Class FileName : public string {
...
Void compose (const string &str, int no, const string &ext)
   *this=(FileName) str;
   if (no!=-1) {
      char aux_str[5];
      sprintf(aux_str,"%05d",no);
      *this += aux_str;
   }

   if (ext!="") *this += "."+ext;
   else REPORT_ERROR(1005,"compose: need a extension");
}
...

I no have any idea for export de class string in C++ to the class
string in Python and the error I see the follow page
http://www.boost.org/libs/python/doc/tutorial/doc/html/python/exception.html
that shows how catch the error but I do it and the problem persist,
someone can help,

I put the solution in a file who contains the BOOST_PYTHON_MODULE
macro like this follow lines"

#include <boost/python.hpp>
using namespace boost::python;

struct PodBayDoorException;

void brack(PodBayDoorException const& x)
{PyErr_SetString(PyExc_UserWarning, x);}

extern void port2python_func();

BOOST_PYTHON_MODULE(_nulo) {
register_exception_translator<PodBayDoorException>(brack);
port2python_func();
...
}

Thanks,



More information about the Cplusplus-sig mailing list