From 7ce2985fe0d7eb24f2c42644ba6055d1bb63fca0 Mon Sep 17 00:00:00 2001 From: Gordon Sim Date: Wed, 31 Aug 2011 08:42:23 +0000 Subject: QPID-3333: Patch from Anthony Foglia - Wrap more exceptions (0009) git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1163526 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/bindings/qpid/python/python.i | 41 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'cpp') diff --git a/cpp/bindings/qpid/python/python.i b/cpp/bindings/qpid/python/python.i index 2eeaf4989e..85801d1737 100644 --- a/cpp/bindings/qpid/python/python.i +++ b/cpp/bindings/qpid/python/python.i @@ -25,8 +25,19 @@ * convert uint8_t by default. */ %apply unsigned char { uint8_t }; + +/* + * Exceptions + * + * The convention below is that exceptions in _cqpid.so have the same + * names as in the C++ library. They get renamed to their Python + * equivalents when brought into the Python wrapping + */ %{ -static PyObject* pNoMessageAvailable; +static PyObject* pNoMessageAvailable; +static PyObject* pTargetCapacityExceeded; +static PyObject* pNotFound; +static PyObject* pTransportFailure; %} %init %{ @@ -34,10 +45,28 @@ static PyObject* pNoMessageAvailable; "_cqpid.NoMessageAvailable", NULL, NULL); Py_INCREF(pNoMessageAvailable); PyModule_AddObject(m, "NoMessageAvailable", pNoMessageAvailable); + + pTargetCapacityExceeded = PyErr_NewException( + "_cqpid.TargetCapacityExceeded", NULL, NULL); + Py_INCREF(pTargetCapacityExceeded); + PyModule_AddObject(m, "TargetCapacityExceeded", pTargetCapacityExceeded); + + pNotFound = PyErr_NewException( + "_cqpid.NotFound", NULL, NULL); + Py_INCREF(pNotFound); + PyModule_AddObject(m, "NotFound", pNotFound); + + pTransportFailure = PyErr_NewException( + "_cqpid.TransportFailure", NULL, NULL); + Py_INCREF(pTransportFailure); + PyModule_AddObject(m, "TransportFailure", pTransportFailure); %} %pythoncode %{ Empty = _cqpid.NoMessageAvailable + TargetCapacityExceeded = _cqpid.TargetCapacityExceeded + NotFound = _cqpid.NotFound + ConnectError = _cqpid.TransportFailure %} /* Define the general-purpose exception handling */ @@ -50,6 +79,15 @@ static PyObject* pNoMessageAvailable; } catch (qpid::messaging::NoMessageAvailable & ex) { pExceptionType = pNoMessageAvailable; error = ex.what(); + } catch (qpid::messaging::TargetCapacityExceeded & ex) { + pExceptionType = pTargetCapacityExceeded; + error = ex.what(); + } catch (qpid::messaging::NotFound & ex) { + pExceptionType = pNotFound; + error = ex.what(); + } catch (qpid::messaging::TransportFailure & ex) { + pExceptionType = pTransportFailure; + error = ex.what(); } catch (qpid::types::Exception& ex) { pExceptionType = PyExc_RuntimeError; error = ex.what(); @@ -61,6 +99,7 @@ static PyObject* pNoMessageAvailable; } } + /* This only renames the non-const version (I believe). Then again, I * don't even know why there is a non-const version of the method. */ %rename(opened) qpid::messaging::Connection::isOpen(); -- cgit v1.2.1