diff options
author | Gordon Sim <gsim@apache.org> | 2011-08-31 08:42:23 +0000 |
---|---|---|
committer | Gordon Sim <gsim@apache.org> | 2011-08-31 08:42:23 +0000 |
commit | f220c7be4b46a1360f7dcf71750ed3dee828e084 (patch) | |
tree | 5e81b936da10a4226d95e0910e7b5012edf21e4e | |
parent | 470263db26077fab21685355316eb35e71b54b5e (diff) | |
download | qpid-python-f220c7be4b46a1360f7dcf71750ed3dee828e084.tar.gz |
QPID-3333: Patch from Anthony Foglia - Wrap more exceptions (0009)
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1163526 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | qpid/cpp/bindings/qpid/python/python.i | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/qpid/cpp/bindings/qpid/python/python.i b/qpid/cpp/bindings/qpid/python/python.i index 2eeaf4989e..85801d1737 100644 --- a/qpid/cpp/bindings/qpid/python/python.i +++ b/qpid/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(); |