|
From: Marcelo M. <mm...@ac...> - 2005-11-24 20:33:04
|
You need to tell swig that your classes are "exception classes", using:
%feature("exceptionclass") exc1;
or
%exceptionclass exc1;
note that python need a special wrapping for these classes, and
while swig tries to identify them by looking at the throw statement
(and hence swig identifies 'exc2'), sometimes, as in your case, you need to
provide the extra hint.
anyway, are you sure about the throw(exc2) statement?, I think you will get
an error if you throw an exception of type 'exc1', unless you provide an
extra
conversion/constructor between 'exc1' and 'exc2'.
Also, try to use the CVS version, and you will avoid to deal with the
auxiliary
exc1Ptr and exc2Ptr classes, which are not generated anymore.
Marcelo
Michael Krasnyk wrote:
> Hello all,
>
> I'm trying to make wrapper for some tree of exceptions.
> With Python exceptions it works like:
> ---------------------------
> class exc1:
> pass
> class exc2(exc1):
> pass
> try:
> raise exc2
> except exc1,exc:
> print "catched"
> ---------------------------
>
> For c++, for example, header is
> ---------------------------
> #include <string>
>
> class exc1 {
> public:
> exc1(std::string _str);
> std::string str;
> };
>
> class exc2 : public exc1 {
> public:
> exc2(std::string _str, int _num);
> std::string str;
> int num;
> };
>
> class test {
> public:
> void callTest() throw (exc2);
> };
> ---------------------------
>
>
> source file:
> ---------------------------
> #include <string>
> #include "exc.hpp"
>
> exc1::exc1(std::string _str) : str(_str){};
> exc2::exc2(std::string _str, int _num) : exc1(_str), num(_num) {};
> void test::callTest() throw (exc2) { throw exc2("exc test", 1); };
> ----------------------------
>
> SWIG i file
> ---------------------------
> %{
> #include <string>
> #include "exc.hpp"
> %}
> %include "exc.hpp"
> ---------------------------
>
> Command lines:
> ---------------------------
> swig -python -c++ -module test exc.i
> g++ -I/usr/local/include/python2.4 -Wl,-rpath-link=/usr/local/lib
> -L/usr/local/lib -lpython2.4\
> -shared exc_wrap.cxx exc.cpp -o _test.so
> ---------------------------
>
> and Python script
> ---------------------------
> from test import *
> t=test()
> try:
> t.callTest()
> except exc2Ptr, exc:
> #except exc2, exc:
> #except exc1Ptr, exc:
> # except exc1, exc:
> print "catched"
> ---------------------------
>
> In my case in Python possible to catch only exc2Ptr.
> And how it's possible to catch exceptions exc2, exc1Ptr, exc1?
> In all three cases Python says: "SystemError: 'finally' pops bad
> exception".
>
> What I'm doing wrong here?
>
> TIA,
> Michael Krasnyk
>
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep through log
> files
> for problems? Stop! Download the new AJAX search engine that makes
> searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
> http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
> _______________________________________________
> Swig-user mailing list
> Swi...@li...
> https://lists.sourceforge.net/lists/listinfo/swig-user
|