exception.hh 1.05 KB
Newer Older
1
2
3
// Copyright 2010, Florent Lamiraux, Thomas Moulard, LAAS-CNRS.

#ifndef DYNAMIC_GRAPH_PYTHON_EXCEPTION
Guilhem Saurel's avatar
format    
Guilhem Saurel committed
4
#define DYNAMIC_GRAPH_PYTHON_EXCEPTION
5

6
7
#include "dynamic-graph/python/dynamic-graph-py.hh"

8
9
/// \brief Catch all exceptions which may be sent when C++ code is
/// called.
Guilhem Saurel's avatar
format    
Guilhem Saurel committed
10
11
#define CATCH_ALL_EXCEPTIONS()                       \
  catch (const std::exception& exc) {                \
Guilhem Saurel's avatar
Guilhem Saurel committed
12
    PyErr_SetString(DGPYERROR, exc.what());          \
Guilhem Saurel's avatar
format    
Guilhem Saurel committed
13
14
15
    return NULL;                                     \
  }                                                  \
  catch (const char* s) {                            \
Guilhem Saurel's avatar
Guilhem Saurel committed
16
    PyErr_SetString(DGPYERROR, s);                   \
Guilhem Saurel's avatar
format    
Guilhem Saurel committed
17
18
19
    return NULL;                                     \
  }                                                  \
  catch (...) {                                      \
Guilhem Saurel's avatar
Guilhem Saurel committed
20
    PyErr_SetString(DGPYERROR, "Unknown exception"); \
Guilhem Saurel's avatar
format    
Guilhem Saurel committed
21
22
23
    return NULL;                                     \
  }                                                  \
  struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n
24

Guilhem Saurel's avatar
format    
Guilhem Saurel committed
25
#endif  //! DYNAMIC_GRAPH_PYTHON_EXCEPTION