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 | 7ce2985fe0d7eb24f2c42644ba6055d1bb63fca0 (patch) | |
| tree | 44a67ec9ed3af6bccac97cf024753ab70cddc921 /cpp/bindings/qpid/python | |
| parent | 7b6796e8686e2a2e4a818693d10bf5367b39ce11 (diff) | |
| download | qpid-python-7ce2985fe0d7eb24f2c42644ba6055d1bb63fca0.tar.gz | |
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
Diffstat (limited to 'cpp/bindings/qpid/python')
| -rw-r--r-- | cpp/bindings/qpid/python/python.i | 41 |
1 files changed, 40 insertions, 1 deletions
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(); |
