Michele De Stefano's C++ Utilities
common.i
1 // mds_utils/python/common.i
2 //
3 // Copyright (c) 2014 - Michele De Stefano (micdestefano@users.sourceforge.net)
4 //
5 // Distributed under the MIT License (See accompanying file LICENSE)
6 
7 %include exception.i
8 
9 %header %{
10 
11 #include <mds_utils/python/exception.hpp>
12 
13 %}
14 
15 // Generic exception handler
16 %exception {
17  try {
18  $action
19  } catch (std::exception& e) {
20  SWIG_exception(SWIG_RuntimeError,e.what());
21  }
22 }
23 
24 // Exception handler specific for the __getitem__ method
25 %exception __getitem__ {
26  try {
27  $action
28  } catch (mds_utils::python::index_error& e) {
29  SWIG_exception(SWIG_IndexError,e.what());
30  } catch (std::exception& e) {
31  SWIG_exception(SWIG_RuntimeError,e.what());
32  }
33 }
34 
35 
36 // Exception handler specific for the py_get_item method
37 %exception py_get_item {
38  try {
39  $action
40  } catch (mds_utils::python::index_error& e) {
41  SWIG_exception(SWIG_IndexError,e.what());
42  } catch (std::exception& e) {
43  SWIG_exception(SWIG_RuntimeError,e.what());
44  }
45 }