/trunk/Lib/typemaps/std_except.swg
Unknown | 96 lines | 79 code | 17 blank | 0 comment | 0 complexity | be1e4d0275c3c5f51e405c1065575e36 MD5 | raw file
1%include <typemaps/exception.swg> 2%include <std/std_except.i> 3 4/* 5 Mark all of std exception classes as "exception classes" via 6 the "exceptionclass" feature. 7 8 If needed, you can disable it by using %noexceptionclass. 9*/ 10 11%define %std_exception_map(Exception, Code) 12 %exceptionclass Exception; 13#if !defined(SWIG_STD_EXCEPTIONS_AS_CLASSES) 14 %typemap(throws,noblock=1) Exception { 15 SWIG_exception_fail(Code, $1.what()); 16 } 17 %ignore Exception; 18 struct Exception { 19 }; 20#endif 21%enddef 22 23namespace std { 24 %std_exception_map(bad_exception, SWIG_SystemError); 25 %std_exception_map(domain_error, SWIG_ValueError); 26 %std_exception_map(exception, SWIG_SystemError); 27 %std_exception_map(invalid_argument, SWIG_ValueError); 28 %std_exception_map(length_error, SWIG_IndexError); 29 %std_exception_map(logic_error, SWIG_RuntimeError); 30 %std_exception_map(out_of_range, SWIG_IndexError); 31 %std_exception_map(overflow_error, SWIG_OverflowError); 32 %std_exception_map(range_error, SWIG_OverflowError); 33 %std_exception_map(runtime_error, SWIG_RuntimeError); 34 %std_exception_map(underflow_error, SWIG_OverflowError); 35} 36 37#if defined(SWIG_STD_EXCEPTIONS_AS_CLASSES) 38 39namespace std { 40 struct exception 41 { 42 virtual ~exception() throw(); 43 virtual const char* what() const throw(); 44 }; 45 46 struct bad_exception : exception 47 { 48 }; 49 50 struct logic_error : exception 51 { 52 logic_error(const string& msg); 53 }; 54 55 struct domain_error : logic_error 56 { 57 domain_error(const string& msg); 58 }; 59 60 struct invalid_argument : logic_error 61 { 62 invalid_argument(const string& msg); 63 }; 64 65 struct length_error : logic_error 66 { 67 length_error(const string& msg); 68 }; 69 70 struct out_of_range : logic_error 71 { 72 out_of_range(const string& msg); 73 }; 74 75 struct runtime_error : exception 76 { 77 runtime_error(const string& msg); 78 }; 79 80 struct range_error : runtime_error 81 { 82 range_error(const string& msg); 83 }; 84 85 struct overflow_error : runtime_error 86 { 87 overflow_error(const string& msg); 88 }; 89 90 struct underflow_error : runtime_error 91 { 92 underflow_error(const string& msg); 93 }; 94} 95 96#endif