Home | History | Annotate | Download | only in 2.0.11
      1 /* -----------------------------------------------------------------------------
      2  * std_except.i
      3  *
      4  * SWIG library file with typemaps to handle and throw STD exceptions in a
      5  * language and STL independent way, i.e., the target language doesn't
      6  * require to support STL but only the 'exception.i' mechanism.
      7  *
      8  * These typemaps are used when methods are declared with an STD
      9  * exception specification, such as
     10  *
     11  *   size_t at() const throw (std::out_of_range);
     12  *
     13  * The typemaps here are based on the language independent
     14  * 'exception.i' library. If that is working in your target language,
     15  * this file will work.
     16  *
     17  * If the target language doesn't implement a robust 'exception.i'
     18  * mechanism, or you prefer other ways to map the STD exceptions, write
     19  * a new std_except.i file in the target library directory.
     20  * ----------------------------------------------------------------------------- */
     21 
     22 #if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGGUILE) || defined(SWIGUTL) || defined(SWIGD)
     23 #error "This version of std_except.i should not be used"
     24 #endif
     25 
     26 %{
     27 #include <stdexcept>
     28 %}
     29 
     30 %include <exception.i>
     31 
     32 
     33 %define %std_exception_map(Exception, Code)
     34   %typemap(throws,noblock=1) Exception {
     35     SWIG_exception(Code, $1.what());
     36   }
     37   %ignore Exception;
     38   struct Exception {
     39   };
     40 %enddef
     41 
     42 namespace std {
     43   %std_exception_map(bad_exception,      SWIG_SystemError);
     44   %std_exception_map(domain_error,       SWIG_ValueError);
     45   %std_exception_map(exception,          SWIG_SystemError);
     46   %std_exception_map(invalid_argument,   SWIG_ValueError);
     47   %std_exception_map(length_error,       SWIG_IndexError);
     48   %std_exception_map(logic_error,        SWIG_RuntimeError);
     49   %std_exception_map(out_of_range,       SWIG_IndexError);
     50   %std_exception_map(overflow_error,     SWIG_OverflowError);
     51   %std_exception_map(range_error,        SWIG_OverflowError);
     52   %std_exception_map(runtime_error,      SWIG_RuntimeError);
     53   %std_exception_map(underflow_error,    SWIG_OverflowError);
     54 }
     55 
     56