~ubuntu-branches/ubuntu/hardy/swig1.3/hardy

« back to all changes in this revision

Viewing changes to Examples/python/exceptshadow/example.i

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-12-05 01:16:04 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051205011604-ygx904it6413k3go
Tags: 1.3.27-1ubuntu1
Resynchronise with Debian again, for the new subversion packages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
   the handler for any class with this method defined.
27
27
*/
28
28
 
 
29
/*
 
30
  First we need to 'disable' the default swig throw mechanism for the
 
31
  FullError class. We do this by rethrowing the exception.
 
32
 
 
33
  Note that this is necessary since the class appears in a throw
 
34
  declaration:
 
35
 
 
36
 
 
37
    void enqueue(T x) throw(FullError);
 
38
 
 
39
  hence, swig recognizes it as an exception class and it will generate
 
40
  the necessary code to catch it and rethrow it to the python side.
 
41
   
 
42
*/
 
43
%typemap(throws) FullError "(void)$1; throw;";
 
44
 
 
45
 
29
46
%exception *::enqueue {
30
47
   try {
31
48
      $action
32
 
   } catch(FullError e) {
 
49
   } catch(FullError& e) {
33
50
      FullError *ecopy = new FullError(e);
34
51
      PyObject *err = SWIG_NewPointerObj(ecopy, SWIGTYPE_p_FullError, 1);
35
52
      PyErr_SetObject((PyObject *) SWIGTYPE_p_FullError->clientdata, err);
58
75
       PyErr_SetObject()!   A neat trick perhaps.
59
76
*/
60
77
 
 
78
/*
 
79
  Now, the EmpytError doesn't appear in a throw declaration, and hence
 
80
  we need to 'mark' it as an exception class. In python, classes that 
 
81
  are used as exception are 'special', and need to be wrapped as
 
82
  'classic' ones.
 
83
 
 
84
  This is a python issue, and if you don't mark the class, you will
 
85
  see 'interesting' behaviours at the python side.
 
86
  
 
87
 
 
88
*/
 
89
%exceptionclass EmptyError;
 
90
 
61
91
%exception *::dequeue {
62
92
   try {
63
93
      $action
64
 
   } catch(EmptyError e) {
 
94
   } catch(EmptyError& e) {
65
95
      EmptyError *ecopy = new EmptyError(e);
66
96
      PyObject *err = SWIG_NewPointerObj(ecopy, SWIGTYPE_p_EmptyError, 1);
67
97
      PyErr_SetObject((PyObject *) SWIGTYPE_p_EmptyError->clientdata, err);