43#ifndef LASS_GUARDIAN_OF_INCLUSION_PYTHON_EXCEPTION_H
44#define LASS_GUARDIAN_OF_INCLUSION_PYTHON_EXCEPTION_H
76class PythonException:
public util::ExceptionMixin<PythonException>
80 LASS_PYTHON_DLL PythonException(PyObject* type,
const std::string& msg, std::string loc);
81 LASS_PYTHON_DLL PythonException(PyObject* type,
const std::string& msg);
83 ~PythonException()
noexcept {}
88 static LASS_PYTHON_DLL
const std::string LASS_CALL extractMessage(PyObject* type, PyObject* value = 0);
124LASS_PYTHON_DLL PyObject* LASS_CALL
chainErrFormat(PyObject* exception,
const char* format, ...);
133LASS_PYTHON_DLL PyObject* LASS_CALL
chainErrFormatV(PyObject* exception,
const char* format, va_list vargs);
180 LASS_PYTHON_DLL
void LASS_CALL
handleException(std::exception_ptr error);
197 template <
typename T,
typename C>
198 static void raise(
const T&,
const C&,
const std::string& message,
const char* locus)
201 if (PyErr_Occurred())
205 if (!message.empty())
217#define LASS_PYTHON_CATCH_AND_RETURN_EX(v_errorReturnValue)\
218 catch (const ::std::exception&)\
220 ::lass::python::impl::handleException(std::current_exception());\
221 return v_errorReturnValue;\
224#define LASS_PYTHON_CATCH_AND_RETURN\
225 LASS_PYTHON_CATCH_AND_RETURN_EX(0)
236#define PY_ENFORCE_POINTER(pointer)\
237 *LASS_UTIL_IMPL_MAKE_ENFORCER(\
238 ::lass::util::impl::TruePredicate,\
239 ::lass::python::impl::PythonFetchRaiser,\
242 "'" LASS_STRINGIFY(pointer) "' in " LASS_HERE)
253#define PY_ENFORCE_ZERO(expression)\
254 *LASS_UTIL_IMPL_MAKE_ENFORCER(\
255 ::lass::util::impl::EqualPredicate,\
256 ::lass::python::impl::PythonFetchRaiser,\
259 "'" LASS_STRINGIFY(expression) "' in " LASS_HERE)
270#define PY_ENFORCE_NOTZERO(expression)\
271 *LASS_UTIL_IMPL_MAKE_ENFORCER(\
272 ::lass::util::impl::UnequalPredicate,\
273 ::lass::python::impl::PythonFetchRaiser,\
276 "'" LASS_STRINGIFY(expression) "' in " LASS_HERE)
acquire the GIL for the current scope.
C++ exception type that holds a Python exception.
void addMessageHeader(const char *header)
Prepend a message to the current Python exception value.
void handleException(std::exception_ptr ptr)
Handle a C++ exception by raising an Python exception.
void fetchAndThrowPythonException(std::string loc)
Fetch the current Python exception and throw it as a C++ PythonException.
PyObject * chainErrFormat(PyObject *exception, const char *format,...)
Raise an explicitly chained Python exception.
PyObject * chainErrFormatV(PyObject *exception, const char *format, va_list vargs)
Raise an explicitly chained Python exception.
PyObjectPtr< PyObject >::Type TPyObjPtr
PyObjectPtr to a PyObject.
Comprehensive C++ to Python binding library.
Library for Assembled Shared Sources.
Raiser type for enforcers that raises a Python exception.