1 /* -----------------------------------------------------------------------------
2 * See the LICENSE file for information on copyright, usage and redistribution
3 * of SWIG, and the README file for authors - http://www.swig.org/release.html.
7 * This SWIG library file provides language independent exception handling
8 * ----------------------------------------------------------------------------- */
10 %include <typemaps/swigmacros.swg>
13 /* macros for error manipulation */
14 #define %nullref_fmt() "invalid null reference "
15 #define %varfail_fmt(_type,_name) "in variable '"`_name`"' of type '"`_type`"'"
17 #define %argfail_fmt(_type,_name,_argn) "in method '" `_name` "', argument " `_argn`" of type '" `_type`"'"
19 #define %outfail_fmt(_type) "in output value of type '"_type"'"
20 #ifndef %argnullref_fmt
21 #define %argnullref_fmt(_type,_name,_argn) %nullref_fmt() %argfail_fmt(_type, _name, _argn)
23 #define %varnullref_fmt(_type,_name) %nullref_fmt() %varfail_fmt(_type, _name)
24 #define %outnullref_fmt(_type) %nullref_fmt() %outfail_fmt(_type)
26 /* setting an error */
27 #define %error(code,msg...) SWIG_Error(code, msg)
28 #define %type_error(msg...) SWIG_Error(SWIG_TypeError, msg)
34 %define_as(SWIG_exception_fail(code, msg), %block(%error(code, msg); SWIG_fail))
36 %define_as(SWIG_contract_assert(expr, msg), if (!(expr)) { %error(SWIG_RuntimeError, msg); SWIG_fail; } else)
42 You can use the SWIG_CATCH_STDEXCEPT macro with the %exception
49 catch (my_except& e) {
52 SWIG_CATCH_STDEXCEPT // catch std::exception
54 SWIG_exception_fail(SWIG_UnknownError, "Unknown exception");
61 %define SWIG_CATCH_STDEXCEPT
62 /* catching std::exception */
63 catch (std::invalid_argument& e) {
64 SWIG_exception_fail(SWIG_ValueError, e.what() );
65 } catch (std::domain_error& e) {
66 SWIG_exception_fail(SWIG_ValueError, e.what() );
67 } catch (std::overflow_error& e) {
68 SWIG_exception_fail(SWIG_OverflowError, e.what() );
69 } catch (std::out_of_range& e) {
70 SWIG_exception_fail(SWIG_IndexError, e.what() );
71 } catch (std::length_error& e) {
72 SWIG_exception_fail(SWIG_IndexError, e.what() );
73 } catch (std::runtime_error& e) {
74 SWIG_exception_fail(SWIG_RuntimeError, e.what() );
75 } catch (std::exception& e) {
76 SWIG_exception_fail(SWIG_SystemError, e.what() );
79 %define SWIG_CATCH_UNKNOWN
80 catch (std::exception& e) {
81 SWIG_exception_fail(SWIG_SystemError, e.what() );
84 SWIG_exception_fail(SWIG_UnknownError, "unknown exception");
89 #endif /* __cplusplus */