]>
Commit | Line | Data |
---|---|---|
c90f71dd RD |
1 | // |
2 | // except.i | |
3 | // Dave Beazley | |
4 | // April 14, 1997 | |
5 | // | |
6 | // This SWIG library file provides language independent exception handling | |
7 | ||
8 | #ifdef AUTODOC | |
9 | %section "Exception Handling Library",info,after,pre,nosort,skip=1,chop_left=3,chop_right=0,chop_top=0,chop_bottom=0 | |
10 | ||
11 | %text %{ | |
12 | %include exception.i | |
13 | ||
14 | This library provides language independent support for raising scripting | |
15 | language exceptions in SWIG generated wrapper code. Normally, this is | |
16 | used in conjunction with the %except directive. | |
17 | ||
18 | To raise an exception, use the following function call : | |
19 | ||
20 | SWIG_exception(int exctype, char *msg); | |
21 | ||
22 | 'exctype' is an exception type code and may be one of the following : | |
23 | ||
24 | SWIG_MemoryError | |
25 | SWIG_IOError | |
26 | SWIG_RuntimeError | |
27 | SWIG_IndexError | |
28 | SWIG_TypeError | |
29 | SWIG_DivisionByZero | |
30 | SWIG_OverflowError | |
31 | SWIG_SyntaxError | |
32 | SWIG_ValueError | |
33 | SWIG_SystemError | |
34 | SWIG_UnknownError | |
35 | ||
36 | 'msg' is an error string that should be reported to the user. | |
37 | ||
38 | The library is normally used in conjunction with the %except directive | |
39 | as follows : | |
40 | ||
41 | %except { | |
42 | try { | |
43 | $function | |
44 | } catch RangeError { | |
45 | SWIG_exception(SWIG_IndexError,"Array index out of bounds"); | |
46 | } catch(...) { | |
47 | SWIG_exception(SWIG_UnknownError,"Uncaught exception"); | |
48 | } | |
49 | } | |
50 | ||
51 | It is important to note that the SWIG_exception() function is only available | |
52 | to the C code generated by SWIG. It is not available in the scripting language | |
53 | interface itself. | |
54 | %} | |
55 | ||
56 | #endif | |
57 | ||
58 | %{ | |
59 | #define SWIG_MemoryError 1 | |
60 | #define SWIG_IOError 2 | |
61 | #define SWIG_RuntimeError 3 | |
62 | #define SWIG_IndexError 4 | |
63 | #define SWIG_TypeError 5 | |
64 | #define SWIG_DivisionByZero 6 | |
65 | #define SWIG_OverflowError 7 | |
66 | #define SWIG_SyntaxError 8 | |
67 | #define SWIG_ValueError 9 | |
68 | #define SWIG_SystemError 10 | |
69 | #define SWIG_UnknownError 99 | |
70 | %} | |
71 | ||
72 | #ifdef SWIGTCL8 | |
73 | %{ | |
74 | #define SWIG_exception(a,b) Tcl_SetStringObj(tcl_result,b,-1); return TCL_ERROR | |
75 | %} | |
76 | #else | |
77 | #ifdef SWIGTCL | |
78 | %{ | |
79 | #define SWIG_exception(a,b) Tcl_SetResult(interp,b,TCL_VOLATILE); return TCL_ERROR | |
80 | %} | |
81 | #endif | |
82 | #endif | |
83 | ||
84 | #ifdef SWIGPERL5 | |
85 | %{ | |
86 | #define SWIG_exception(a,b) croak(b) | |
87 | %} | |
88 | #endif | |
89 | ||
90 | #ifdef SWIGPERL4 | |
91 | %{ | |
92 | #define SWIG_exception(a,b) fatal(b) | |
93 | %} | |
94 | #endif | |
95 | ||
96 | #ifdef SWIGPYTHON | |
97 | %{ | |
98 | static void _SWIG_exception(int code, char *msg) { | |
99 | switch(code) { | |
100 | case SWIG_MemoryError: | |
101 | PyErr_SetString(PyExc_MemoryError,msg); | |
102 | break; | |
103 | case SWIG_IOError: | |
104 | PyErr_SetString(PyExc_IOError,msg); | |
105 | break; | |
106 | case SWIG_RuntimeError: | |
107 | PyErr_SetString(PyExc_RuntimeError,msg); | |
108 | break; | |
109 | case SWIG_IndexError: | |
110 | PyErr_SetString(PyExc_IndexError,msg); | |
111 | break; | |
112 | case SWIG_TypeError: | |
113 | PyErr_SetString(PyExc_TypeError,msg); | |
114 | break; | |
115 | case SWIG_DivisionByZero: | |
116 | PyErr_SetString(PyExc_ZeroDivisionError,msg); | |
117 | break; | |
118 | case SWIG_OverflowError: | |
119 | PyErr_SetString(PyExc_OverflowError,msg); | |
120 | break; | |
121 | case SWIG_SyntaxError: | |
122 | PyErr_SetString(PyExc_SyntaxError,msg); | |
123 | break; | |
124 | case SWIG_ValueError: | |
125 | PyErr_SetString(PyExc_ValueError,msg); | |
126 | break; | |
127 | case SWIG_SystemError: | |
128 | PyErr_SetString(PyExc_SystemError,msg); | |
129 | break; | |
130 | default: | |
131 | PyErr_SetString(PyExc_RuntimeError,msg); | |
132 | break; | |
133 | } | |
134 | } | |
135 | ||
136 | #define SWIG_exception(a,b) _SWIG_exception(a,b); return NULL | |
137 | %} | |
138 | #endif | |
139 | ||
140 | #ifdef SWIGGUILE | |
141 | %echo %{ | |
142 | exception.i : Guile not currently supported. | |
143 | %} | |
144 | #endif | |
145 | ||
146 |