]> Creatis software - gdcm.git/blob - Testing/ExceptionAndPython/README
6e9fd69ee566f4e52a6549a4d360567ac5bde1da
[gdcm.git] / Testing / ExceptionAndPython / README
1 The purpous of this set of files is to illustrate an unexpected behavior
2 of exception handling of swig wrapped c++ libraries with wxPython.
3 Context:
4  - g++ version 2.96 or 3.2
5  - swig version 1.3.16u
6  - python2.2
7
8 Consider the code in one of the foo_main.cxx say foo_main.cxx.minimal:
9         #include <iostream>
10         
11         void MyWrappedFunction(void) {
12            try { throw "In thrower"; }
13            catch (const char * str) { cout<<"Exception"<< str << endl; }
14         }
15         
16         int main() {
17                 MyWrappedFunction();
18                 return 0;
19         }
20 When compiling this code and executing it one obtains the correct behavior
21 of the exception i.e. ExceptionIn thrower.
22 Now, wrap the above code with swig and invoque the following python
23 script (see test.py):
24   import wxPython.wx
25   import foo
26   foo.MyWrappedFunction()
27 Surprisingly enough the exception won't be caugth, but terminate will
28 catch it and invoke abort.
29 Note that the exception is properly caught when one doesn't import 
30 wxPython.
31 Note that the exception is properly caught when one doesn't import 
32 wxPython.
33
34 In order to play with this example, try the following:
35 ln -s foo_main.cxx.minimal foo_main.cxx 
36 ln -s foo.cxx.minimal foo.cxx 
37 make
38 ./main
39 ExceptionIn thrower
40 python test.py
41