1 /* ----------------------------------------------------------------------------- 2 * exception.i 3 * 4 * SWIG library file providing language independent exception handling 5 * ----------------------------------------------------------------------------- */ 6 7 #if defined(SWIGUTL) 8 #error "This version of exception.i should not be used" 9 #endif 10 11 12 %insert("runtime") "swigerrors.swg" 13 14 15 #ifdef SWIGPHP 16 %{ 17 #include "zend_exceptions.h" 18 #define SWIG_exception(code, msg) { zend_throw_exception(NULL, (char*)msg, code TSRMLS_CC); } 19 %} 20 #endif 21 22 #ifdef SWIGGUILE 23 %{ 24 SWIGINTERN void SWIG_exception_ (int code, const char *msg, 25 const char *subr) { 26 #define ERROR(scmerr) \ 27 scm_error(scm_from_locale_string((char *) (scmerr)), \ 28 (char *) subr, (char *) msg, \ 29 SCM_EOL, SCM_BOOL_F) 30 #define MAP(swigerr, scmerr) \ 31 case swigerr: \ 32 ERROR(scmerr); \ 33 break 34 switch (code) { 35 MAP(SWIG_MemoryError, "swig-memory-error"); 36 MAP(SWIG_IOError, "swig-io-error"); 37 MAP(SWIG_RuntimeError, "swig-runtime-error"); 38 MAP(SWIG_IndexError, "swig-index-error"); 39 MAP(SWIG_TypeError, "swig-type-error"); 40 MAP(SWIG_DivisionByZero, "swig-division-by-zero"); 41 MAP(SWIG_OverflowError, "swig-overflow-error"); 42 MAP(SWIG_SyntaxError, "swig-syntax-error"); 43 MAP(SWIG_ValueError, "swig-value-error"); 44 MAP(SWIG_SystemError, "swig-system-error"); 45 default: 46 ERROR("swig-error"); 47 } 48 #undef ERROR 49 #undef MAP 50 } 51 52 #define SWIG_exception(a,b) SWIG_exception_(a, b, FUNC_NAME) 53 %} 54 #endif 55 56 #ifdef SWIGMZSCHEME 57 58 %{ 59 SWIGINTERN void SWIG_exception_ (int code, const char *msg) { 60 #define ERROR(errname) \ 61 scheme_signal_error(errname " (%s)", msg); 62 #define MAP(swigerr, errname) \ 63 case swigerr: \ 64 ERROR(errname); \ 65 break 66 switch (code) { 67 MAP(SWIG_MemoryError, "swig-memory-error"); 68 MAP(SWIG_IOError, "swig-io-error"); 69 MAP(SWIG_RuntimeError, "swig-runtime-error"); 70 MAP(SWIG_IndexError, "swig-index-error"); 71 MAP(SWIG_TypeError, "swig-type-error"); 72 MAP(SWIG_DivisionByZero, "swig-division-by-zero"); 73 MAP(SWIG_OverflowError, "swig-overflow-error"); 74 MAP(SWIG_SyntaxError, "swig-syntax-error"); 75 MAP(SWIG_ValueError, "swig-value-error"); 76 MAP(SWIG_SystemError, "swig-system-error"); 77 default: 78 ERROR("swig-error"); 79 } 80 #undef ERROR 81 #undef MAP 82 } 83 84 #define SWIG_exception(a,b) SWIG_exception_(a, b) 85 %} 86 #endif 87 88 #ifdef SWIGJAVA 89 %{ 90 SWIGINTERN void SWIG_JavaException(JNIEnv *jenv, int code, const char *msg) { 91 SWIG_JavaExceptionCodes exception_code = SWIG_JavaUnknownError; 92 switch(code) { 93 case SWIG_MemoryError: 94 exception_code = SWIG_JavaOutOfMemoryError; 95 break; 96 case SWIG_IOError: 97 exception_code = SWIG_JavaIOException; 98 break; 99 case SWIG_SystemError: 100 case SWIG_RuntimeError: 101 exception_code = SWIG_JavaRuntimeException; 102 break; 103 case SWIG_OverflowError: 104 case SWIG_IndexError: 105 exception_code = SWIG_JavaIndexOutOfBoundsException; 106 break; 107 case SWIG_DivisionByZero: 108 exception_code = SWIG_JavaArithmeticException; 109 break; 110 case SWIG_SyntaxError: 111 case SWIG_ValueError: 112 case SWIG_TypeError: 113 exception_code = SWIG_JavaIllegalArgumentException; 114 break; 115 case SWIG_UnknownError: 116 default: 117 exception_code = SWIG_JavaUnknownError; 118 break; 119 } 120 SWIG_JavaThrowException(jenv, exception_code, msg); 121 } 122 %} 123 124 #define SWIG_exception(code, msg)\ 125 { SWIG_JavaException(jenv, code, msg); return $null; } 126 #endif // SWIGJAVA 127 128 #ifdef SWIGOCAML 129 %{ 130 #define OCAML_MSG_BUF_LEN 1024 131 SWIGINTERN void SWIG_exception_(int code, const char *msg) { 132 char msg_buf[OCAML_MSG_BUF_LEN]; 133 sprintf( msg_buf, "Exception(%d): %s\n", code, msg ); 134 failwith( msg_buf ); 135 } 136 #define SWIG_exception(a,b) SWIG_exception_((a),(b)) 137 %} 138 #endif 139 140 141 #ifdef SWIGCHICKEN 142 %{ 143 SWIGINTERN void SWIG_exception_(int code, const char *msg) { 144 C_word *a; 145 C_word scmmsg; 146 C_word list; 147 148 a = C_alloc (C_SIZEOF_STRING (strlen (msg)) + C_SIZEOF_LIST(2)); 149 scmmsg = C_string2 (&a, (char *) msg); 150 list = C_list(&a, 2, C_fix(code), scmmsg); 151 SWIG_ThrowException(list); 152 } 153 #define SWIG_exception(a,b) SWIG_exception_((a),(b)) 154 %} 155 #endif 156 157 #ifdef SWIGCSHARP 158 %{ 159 SWIGINTERN void SWIG_CSharpException(int code, const char *msg) { 160 if (code == SWIG_ValueError) { 161 SWIG_CSharpExceptionArgumentCodes exception_code = SWIG_CSharpArgumentOutOfRangeException; 162 SWIG_CSharpSetPendingExceptionArgument(exception_code, msg, 0); 163 } else { 164 SWIG_CSharpExceptionCodes exception_code = SWIG_CSharpApplicationException; 165 switch(code) { 166 case SWIG_MemoryError: 167 exception_code = SWIG_CSharpOutOfMemoryException; 168 break; 169 case SWIG_IndexError: 170 exception_code = SWIG_CSharpIndexOutOfRangeException; 171 break; 172 case SWIG_DivisionByZero: 173 exception_code = SWIG_CSharpDivideByZeroException; 174 break; 175 case SWIG_IOError: 176 exception_code = SWIG_CSharpIOException; 177 break; 178 case SWIG_OverflowError: 179 exception_code = SWIG_CSharpOverflowException; 180 break; 181 case SWIG_RuntimeError: 182 case SWIG_TypeError: 183 case SWIG_SyntaxError: 184 case SWIG_SystemError: 185 case SWIG_UnknownError: 186 default: 187 exception_code = SWIG_CSharpApplicationException; 188 break; 189 } 190 SWIG_CSharpSetPendingException(exception_code, msg); 191 } 192 } 193 %} 194 195 #define SWIG_exception(code, msg)\ 196 { SWIG_CSharpException(code, msg); return $null; } 197 #endif // SWIGCSHARP 198 199 #ifdef SWIGLUA 200 201 %{ 202 #define SWIG_exception(a,b)\ 203 { lua_pushfstring(L,"%s:%s",#a,b);SWIG_fail; } 204 %} 205 206 #endif // SWIGLUA 207 208 #ifdef SWIGD 209 %{ 210 SWIGINTERN void SWIG_DThrowException(int code, const char *msg) { 211 SWIG_DExceptionCodes exception_code; 212 switch(code) { 213 case SWIG_IndexError: 214 exception_code = SWIG_DNoSuchElementException; 215 break; 216 case SWIG_IOError: 217 exception_code = SWIG_DIOException; 218 break; 219 case SWIG_ValueError: 220 exception_code = SWIG_DIllegalArgumentException; 221 break; 222 case SWIG_DivisionByZero: 223 case SWIG_MemoryError: 224 case SWIG_OverflowError: 225 case SWIG_RuntimeError: 226 case SWIG_TypeError: 227 case SWIG_SyntaxError: 228 case SWIG_SystemError: 229 case SWIG_UnknownError: 230 default: 231 exception_code = SWIG_DException; 232 break; 233 } 234 SWIG_DSetPendingException(exception_code, msg); 235 } 236 %} 237 238 #define SWIG_exception(code, msg)\ 239 { SWIG_DThrowException(code, msg); return $null; } 240 #endif // SWIGD 241 242 #ifdef __cplusplus 243 /* 244 You can use the SWIG_CATCH_STDEXCEPT macro with the %exception 245 directive as follows: 246 247 %exception { 248 try { 249 $action 250 } 251 catch (my_except& e) { 252 ... 253 } 254 SWIG_CATCH_STDEXCEPT // catch std::exception 255 catch (...) { 256 SWIG_exception(SWIG_UnknownError, "Unknown exception"); 257 } 258 } 259 */ 260 %{ 261 #include <stdexcept> 262 %} 263 %define SWIG_CATCH_STDEXCEPT 264 /* catching std::exception */ 265 catch (std::invalid_argument& e) { 266 SWIG_exception(SWIG_ValueError, e.what() ); 267 } catch (std::domain_error& e) { 268 SWIG_exception(SWIG_ValueError, e.what() ); 269 } catch (std::overflow_error& e) { 270 SWIG_exception(SWIG_OverflowError, e.what() ); 271 } catch (std::out_of_range& e) { 272 SWIG_exception(SWIG_IndexError, e.what() ); 273 } catch (std::length_error& e) { 274 SWIG_exception(SWIG_IndexError, e.what() ); 275 } catch (std::runtime_error& e) { 276 SWIG_exception(SWIG_RuntimeError, e.what() ); 277 } catch (std::exception& e) { 278 SWIG_exception(SWIG_SystemError, e.what() ); 279 } 280 %enddef 281 %define SWIG_CATCH_UNKNOWN 282 catch (std::exception& e) { 283 SWIG_exception(SWIG_SystemError, e.what() ); 284 } 285 catch (...) { 286 SWIG_exception(SWIG_UnknownError, "unknown exception"); 287 } 288 %enddef 289 290 /* rethrow the unknown exception */ 291 292 #if defined(SWIGCSHARP) || defined(SWIGD) 293 %typemap(throws,noblock=1, canthrow=1) (...) { 294 SWIG_exception(SWIG_RuntimeError,"unknown exception"); 295 } 296 #else 297 %typemap(throws,noblock=1) (...) { 298 SWIG_exception(SWIG_RuntimeError,"unknown exception"); 299 } 300 #endif 301 302 #endif /* __cplusplus */ 303 304 /* exception.i ends here */ 305