You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2016/02/26 00:36:39 UTC

[5/6] qpid-proton git commit: PROTON-1138: c++: Clean up error types.

PROTON-1138: c++: Clean up error types.

Removed proton::closed_error
Renamed proton::io_error as proton::connection_engine::io_error
Replaced encode_error, decode_error and type_error with proton::conversion_error


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/8cbde662
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/8cbde662
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/8cbde662

Branch: refs/heads/master
Commit: 8cbde66258b1389c85fc467d5c0ed65301587250
Parents: 6e85708
Author: Alan Conway <ac...@redhat.com>
Authored: Tue Feb 23 12:57:02 2016 -0500
Committer: Alan Conway <ac...@redhat.com>
Committed: Thu Feb 25 17:50:56 2016 -0500

----------------------------------------------------------------------
 examples/cpp/engine/broker.cpp                  |  2 +-
 .../cpp/include/proton/connection_engine.hpp    | 10 +++-
 proton-c/bindings/cpp/include/proton/error.hpp  | 50 ++------------------
 proton-c/bindings/cpp/include/proton/io.hpp     | 12 +++--
 .../bindings/cpp/include/proton/message_id.hpp  |  2 +-
 proton-c/bindings/cpp/include/proton/scalar.hpp |  6 +--
 proton-c/bindings/cpp/include/proton/types.hpp  |  9 ----
 proton-c/bindings/cpp/include/proton/value.hpp  |  2 +-
 proton-c/bindings/cpp/src/connection_engine.cpp |  4 +-
 proton-c/bindings/cpp/src/decoder.cpp           | 24 +++++-----
 proton-c/bindings/cpp/src/encoder.cpp           |  6 +--
 proton-c/bindings/cpp/src/error.cpp             |  9 +---
 proton-c/bindings/cpp/src/interop_test.cpp      | 16 +++----
 proton-c/bindings/cpp/src/posix/io.cpp          |  4 +-
 proton-c/bindings/cpp/src/scalar.cpp            | 10 ++--
 proton-c/bindings/cpp/src/scalar_test.cpp       | 15 +++---
 proton-c/bindings/cpp/src/types.cpp             | 14 ------
 proton-c/bindings/cpp/src/types_internal.hpp    |  9 ++++
 proton-c/bindings/cpp/src/windows/io.cpp        |  6 +--
 19 files changed, 78 insertions(+), 132 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/8cbde662/examples/cpp/engine/broker.cpp
----------------------------------------------------------------------
diff --git a/examples/cpp/engine/broker.cpp b/examples/cpp/engine/broker.cpp
index 528bf86..09345de 100644
--- a/examples/cpp/engine/broker.cpp
+++ b/examples/cpp/engine/broker.cpp
@@ -80,7 +80,7 @@ int main(int argc, char **argv) {
 
 template <class T> T check(T result, const std::string& msg="io_error: ") {
     if (result < 0)
-        throw proton::io_error(msg + proton::io::error_str());
+        throw proton::connection_engine::io_error(msg + proton::io::error_str());
     return result;
 }
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/8cbde662/proton-c/bindings/cpp/include/proton/connection_engine.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/connection_engine.hpp b/proton-c/bindings/cpp/include/proton/connection_engine.hpp
index 0c509d2..4834c18 100644
--- a/proton-c/bindings/cpp/include/proton/connection_engine.hpp
+++ b/proton-c/bindings/cpp/include/proton/connection_engine.hpp
@@ -22,6 +22,7 @@
 
 #include "proton/connection.hpp"
 #include "proton/connection_options.hpp"
+#include "proton/error.hpp"
 #include "proton/export.hpp"
 #include "proton/pn_unique_ptr.hpp"
 #include "proton/types.hpp"
@@ -123,6 +124,11 @@ PN_CPP_CLASS_EXTERN connection_engine {
     /// Get the AMQP connection associated with this connection_engine.
     PN_CPP_EXTERN class connection connection() const;
 
+    /// Thrown by io_read and io_write functions to indicate an error.
+    struct PN_CPP_CLASS_EXTERN io_error : public error {
+        PN_CPP_EXTERN explicit io_error(const std::string&);
+    };
+
   protected:
     /// Do a non-blocking read on the IO stream.
     ///
@@ -130,7 +136,7 @@ PN_CPP_CLASS_EXTERN connection_engine {
     /// size==0 means no data could be read without blocking, the stream is still open.
     /// Returns pair(0, false) if the stream closed.
     ///
-    ///@throw proton::io_error if there is a read error.
+    ///@throw proton::connection_engine::io_error if there is a read error.
     virtual std::pair<size_t, bool> io_read(char* buf, size_t max) = 0;
 
     /// Do a non-blocking write of up to max bytes from buf.
@@ -138,7 +144,7 @@ PN_CPP_CLASS_EXTERN connection_engine {
     /// Return the number of byes written , 0 if no data could be written
     /// without blocking.
     ///
-    ///throw proton::io_error if there is a write error.
+    ///throw proton::connection_engine::io_error if there is a write error.
     virtual size_t io_write(const char*, size_t) = 0;
 
     /// Close the io, no more _io methods will be called after this is called.

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/8cbde662/proton-c/bindings/cpp/include/proton/error.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/error.hpp b/proton-c/bindings/cpp/include/proton/error.hpp
index 6877bcc..b947ba6 100644
--- a/proton-c/bindings/cpp/include/proton/error.hpp
+++ b/proton-c/bindings/cpp/include/proton/error.hpp
@@ -31,67 +31,25 @@
 namespace proton {
 
 /// The base proton error.
-///    
+///
 /// All exceptions thrown from functions in the proton namespace are
 /// subclasses of proton::error.
 struct
 PN_CPP_CLASS_EXTERN error : public std::runtime_error {
-    /// @cond INTERNAL
-    /// XXX do we intend users to construct these (and subclasses)?
-    /// XXX don't need to be extern?
     PN_CPP_EXTERN explicit error(const std::string&);
-    /// @endcond
 };
 
 /// Raised if a timeout expires.
 struct
 PN_CPP_CLASS_EXTERN timeout_error : public error {
-    /// @cond INTERNAL
     PN_CPP_EXTERN explicit timeout_error(const std::string&);
-    /// @endcond
 };
 
-/// @cond INTERNAL
-/// XXX change namespace to proton::amqp with encoder and decoder?
-
-/// Raised if there is an error decoding AMQP data as a C++ value.
-struct
-PN_CPP_CLASS_EXTERN decode_error : public error {
-    PN_CPP_EXTERN explicit decode_error(const std::string&);
-};
-
-/// Raised if there is an error encoding a C++ value as AMQP data.
-struct
-PN_CPP_CLASS_EXTERN encode_error : public error {
-    PN_CPP_EXTERN explicit encode_error(const std::string&);
-};
-
-/// @endcond
-
-/// @cond INTERNAL
-/// XXX need to discuss
-
-/// XXX move this with connection_engine to an io package?
-/// Error reading or writing external IO.
+/// Raised if there is an error converting between AMQP and C++ data.
 struct
-PN_CPP_CLASS_EXTERN io_error : public error {
-    // XXX needs to remain public and exposed - it's part of the connection_engine SPI
-    PN_CPP_EXTERN explicit io_error(const std::string&);
+PN_CPP_CLASS_EXTERN conversion_error : public error {
+    PN_CPP_EXTERN explicit conversion_error(const std::string&);
 };
-
-/// XXX do we need something this fine grained? and is it really an
-/// *io* error?
-/// XXX doesn't appear to be thrown anywhere - consider removing
-/// Attempt to use a closed resource (connnection, session, or link).
-/// XXX decision - remove
-struct
-PN_CPP_CLASS_EXTERN closed_error : public io_error {
-    PN_CPP_EXTERN explicit closed_error(const std::string& = default_msg);
-    static const std::string default_msg;
-};
-
-/// @endcond
-
 }
 
 #endif // PROTON_CPP_EXCEPTIONS_H

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/8cbde662/proton-c/bindings/cpp/include/proton/io.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/io.hpp b/proton-c/bindings/cpp/include/proton/io.hpp
index 63c78a6..e559504 100644
--- a/proton-c/bindings/cpp/include/proton/io.hpp
+++ b/proton-c/bindings/cpp/include/proton/io.hpp
@@ -24,11 +24,13 @@
 
 namespace proton {
 
-/// IO using sockets, file descriptors, or handles.
-
-/// Note that you can use proton::connection_engine to communicate
-/// using AMQP over your own IO implementation or to integrate an
-/// existing IO framework of your choice.
+/// IO using sockets, file descriptors, or handles, for use with
+/// proton::connection_engine.
+///
+/// Note that you can use proton::connection_engine to communicate using AMQP
+/// over your own IO implementation or to integrate an existing IO framework of
+/// your choice, this implementation is provided as a convenience if sockets is
+/// sufficient for your needs.
 
 namespace io {
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/8cbde662/proton-c/bindings/cpp/include/proton/message_id.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/message_id.hpp b/proton-c/bindings/cpp/include/proton/message_id.hpp
index fcfd125..ace58f9 100644
--- a/proton-c/bindings/cpp/include/proton/message_id.hpp
+++ b/proton-c/bindings/cpp/include/proton/message_id.hpp
@@ -62,7 +62,7 @@ class message_id : public restricted_scalar {
     /// @name Get methods
     ///
     /// get(T&) extracts the value if the types match exactly and
-    /// throws type_error otherwise.
+    /// throws conversion_error otherwise.
     ///
     /// @{
     void get(uint64_t& x) const { scalar_.get(x); }

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/8cbde662/proton-c/bindings/cpp/include/proton/scalar.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/scalar.hpp b/proton-c/bindings/cpp/include/proton/scalar.hpp
index 6d8ed8c..822efc6 100644
--- a/proton-c/bindings/cpp/include/proton/scalar.hpp
+++ b/proton-c/bindings/cpp/include/proton/scalar.hpp
@@ -89,7 +89,7 @@ class scalar : private comparable<scalar> {
     /// @name Get methods
     ///
     /// get(T&) extracts the value if the types match exactly and
-    /// throws type_error otherwise.
+    /// throws conversion_error otherwise.
     ///
     /// @{
     PN_CPP_EXTERN void get(bool&) const;
@@ -122,7 +122,7 @@ class scalar : private comparable<scalar> {
     ///
     /// As methods do "loose" conversion.  They will convert the
     /// scalar's value to the requested type if possible, else throw
-    /// type_error.
+    /// conversion_error.
     ///
     /// @{
     PN_CPP_EXTERN int64_t as_int() const;        ///< Allowed if type_id_is_integral(type())
@@ -169,7 +169,7 @@ class restricted_scalar : private comparable<restricted_scalar> {
     ///
     /// As methods do "loose" conversion.  They will convert the
     /// scalar's value to the requested type if possible, else throw
-    /// type_error.
+    /// conversion_error.
     ///
     /// @{
     int64_t as_int() const { return scalar_.as_int(); }

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/8cbde662/proton-c/bindings/cpp/include/proton/types.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/types.hpp b/proton-c/bindings/cpp/include/proton/types.hpp
index 312ac75..c052cd1 100644
--- a/proton-c/bindings/cpp/include/proton/types.hpp
+++ b/proton-c/bindings/cpp/include/proton/types.hpp
@@ -73,15 +73,6 @@ PN_CPP_EXTERN std::ostream& operator<<(std::ostream&, type_id);
 
 /// @cond INTERNAL
 
-/// XXX change namespace
-/// Raised when there is a type mismatch, with the expected and actual
-/// type ID.
-struct type_error : public decode_error {
-    PN_CPP_EXTERN explicit type_error(type_id want, type_id got, const std::string& =std::string());
-    type_id want; ///< Expected type_id
-    type_id got;  ///< Actual type_id
-};
-
 PN_CPP_EXTERN pn_bytes_t pn_bytes(const std::string&);
 PN_CPP_EXTERN std::string str(const pn_bytes_t& b);
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/8cbde662/proton-c/bindings/cpp/include/proton/value.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/value.hpp b/proton-c/bindings/cpp/include/proton/value.hpp
index e6cfec0..8de6962 100644
--- a/proton-c/bindings/cpp/include/proton/value.hpp
+++ b/proton-c/bindings/cpp/include/proton/value.hpp
@@ -91,7 +91,7 @@ class value : private comparable<value> {
     /// @name As methods
     ///
     /// As methods do "loose" conversion, they will convert the scalar
-    /// value to the requested type if possible, else throw type_error.
+    /// value to the requested type if possible, else throw conversion_error.
     ///
     /// @{
     PN_CPP_EXTERN int64_t as_int() const;        ///< Allowed if `type_id_is_integral(type())`

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/8cbde662/proton-c/bindings/cpp/src/connection_engine.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/connection_engine.cpp b/proton-c/bindings/cpp/src/connection_engine.cpp
index a15fe95..043c96e 100644
--- a/proton-c/bindings/cpp/src/connection_engine.cpp
+++ b/proton-c/bindings/cpp/src/connection_engine.cpp
@@ -57,6 +57,8 @@ void close_transport(connection_engine_context *ctx_) {
 std::string  make_id(const std::string s="") { return s.empty() ? uuid::random().str() : s; }
 }
 
+connection_engine::io_error::io_error(const std::string& msg) : error(msg) {}
+
 class connection_engine::container::impl {
   public:
     impl(const std::string s="") : id_(make_id(s)) {}
@@ -189,8 +191,6 @@ void connection_engine::try_write() {
             throw io_error(msg() << "write invalid size: " << n << " > " << max);
         }
         pn_transport_pop(ctx_->transport, n);
-    } catch (const closed_error&) {
-        pn_transport_close_head(ctx_->transport);
     } catch (const io_error& e) {
         set_error(ctx_, e.what());
         pn_transport_close_head(ctx_->transport);

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/8cbde662/proton-c/bindings/cpp/src/decoder.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/decoder.cpp b/proton-c/bindings/cpp/src/decoder.cpp
index 9056674..2246339 100644
--- a/proton-c/bindings/cpp/src/decoder.cpp
+++ b/proton-c/bindings/cpp/src/decoder.cpp
@@ -55,7 +55,7 @@ struct narrow {
 
 template <class T> T check(T result) {
     if (result < 0)
-        throw decode_error("" + error_str(result));
+        throw conversion_error("" + error_str(result));
     return result;
 }
 
@@ -89,13 +89,13 @@ data decoder::data() { return proton::data(pn_object()); }
 namespace {
 
 void bad_type(type_id want, type_id got) {
-    if (want != got) throw type_error(want, got);
+    if (want != got) throw make_conversion_error(want, got);
 }
 
 type_id pre_get(pn_data_t* data) {
-    if (!pn_data_next(data)) throw decode_error("no more data");
+    if (!pn_data_next(data)) throw conversion_error("no more data");
     type_id t = type_id(pn_data_type(data));
-    if (t < 0) throw decode_error("invalid data");
+    if (t < 0) throw conversion_error("invalid data");
     return t;
 }
 
@@ -145,7 +145,7 @@ decoder operator>>(decoder d0, start& s) {
         s.size = 1;
         break;
       default:
-        throw decode_error(MSG("" << s.type << " is not a container type"));
+        throw conversion_error(MSG("" << s.type << " is not a container type"));
     }
     pn_data_enter(d);
     ss.cancel();
@@ -163,12 +163,12 @@ decoder operator>>(decoder d, rewind) { d.rewind(); return d; }
 decoder operator>>(decoder d, value& v) {
     data ddata = d.data();
     data vdata = v.encode().data();
-    if (d.data() == v.data_) throw decode_error("extract into self");
+    if (d.data() == v.data_) throw conversion_error("extract into self");
     {
         narrow n(ddata);
         check(vdata.appendn(ddata, 1));
     }
-    if (!ddata.next()) throw decode_error("no more data");
+    if (!ddata.next()) throw conversion_error("no more data");
     return d;
 }
 
@@ -180,7 +180,7 @@ decoder operator>>(decoder d, message_id& x) {
       case STRING:
         return d >> x.scalar_;
       default:
-        throw decode_error("expected one of ulong, uuid, binary or string but found " +
+        throw conversion_error("expected one of ulong, uuid, binary or string but found " +
                            type_name(d.type()));
     };
 }
@@ -191,7 +191,7 @@ decoder operator>>(decoder d, annotation_key& x) {
       case SYMBOL:
         return d >> x.scalar_;
       default:
-        throw decode_error("expected one of ulong or symbol but found " + type_name(d.type()));
+        throw conversion_error("expected one of ulong or symbol but found " + type_name(d.type()));
     };
 }
 
@@ -205,7 +205,7 @@ decoder operator>>(decoder d, scalar& x) {
     save_state ss(d.pn_object());
     type_id got = pre_get(d.pn_object());
     if (!type_id_is_scalar(got))
-        throw decode_error("expected scalar, found "+type_name(got));
+        throw conversion_error("expected scalar, found "+type_name(got));
     x.set(pn_data_get_atom(d.pn_object()));
     ss.cancel();                // No error, no rewind
     return d;
@@ -385,9 +385,9 @@ decoder operator>>(decoder d0, std::string &x) {
 
 void assert_map_scope(const scope& s) {
     if (s.type != MAP)
-        throw decode_error("cannot decode "+type_name(s.type)+" as map");
+        throw conversion_error("cannot decode "+type_name(s.type)+" as map");
     if (s.size % 2 != 0)
-        throw decode_error("odd number of elements in map");
+        throw conversion_error("odd number of elements in map");
 }
 
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/8cbde662/proton-c/bindings/cpp/src/encoder.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/encoder.cpp b/proton-c/bindings/cpp/src/encoder.cpp
index 58246d7..fd0a1d3 100644
--- a/proton-c/bindings/cpp/src/encoder.cpp
+++ b/proton-c/bindings/cpp/src/encoder.cpp
@@ -45,7 +45,7 @@ struct save_state {
 
 void check(long result, pn_data_t* data) {
     if (result < 0)
-        throw encode_error(error_str(pn_data_error(data), result));
+        throw conversion_error(error_str(pn_data_error(data), result));
 }
 }
 
@@ -90,7 +90,7 @@ encoder operator<<(encoder e, const start& s) {
       case LIST: pn_data_put_list(e.pn_object()); break;
       case DESCRIBED: pn_data_put_described(e.pn_object()); break;
       default:
-        throw encode_error(MSG("" << s.type << " is not a container type"));
+        throw conversion_error(MSG("" << s.type << " is not a container type"));
     }
     pn_data_enter(e.pn_object());
     return e;
@@ -147,7 +147,7 @@ encoder operator<<(encoder e, amqp_binary x) { return insert(e, e.pn_object(), x
 
 encoder operator<<(encoder e, const value& v) {
     data edata = e.data();
-    if (edata == v.data_) throw encode_error("cannot insert into self");
+    if (edata == v.data_) throw conversion_error("cannot insert into self");
     data vdata = v.decode().data();
     check(edata.append(vdata), e.pn_object());
     return e;

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/8cbde662/proton-c/bindings/cpp/src/error.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/error.cpp b/proton-c/bindings/cpp/src/error.cpp
index 1dedab1..28fd9f5 100644
--- a/proton-c/bindings/cpp/src/error.cpp
+++ b/proton-c/bindings/cpp/src/error.cpp
@@ -25,13 +25,6 @@ error::error(const std::string& msg) : std::runtime_error(msg) {}
 
 timeout_error::timeout_error(const std::string& msg) : error(msg) {}
 
-decode_error::decode_error(const std::string& msg) : error("decode: "+msg) {}
-
-encode_error::encode_error(const std::string& msg) : error("encode: "+msg) {}
-
-io_error::io_error(const std::string& msg) : error(msg) {}
-
-closed_error::closed_error(const std::string& msg) : io_error(msg) {}
-const std::string closed_error::default_msg("closed");
+conversion_error::conversion_error(const std::string& msg) : error(msg) {}
 
 }

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/8cbde662/proton-c/bindings/cpp/src/interop_test.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/interop_test.cpp b/proton-c/bindings/cpp/src/interop_test.cpp
index 168677b..9ac162c 100644
--- a/proton-c/bindings/cpp/src/interop_test.cpp
+++ b/proton-c/bindings/cpp/src/interop_test.cpp
@@ -59,22 +59,22 @@ void test_decoder_primitves_exact() {
     dv.decode().decode(read("primitives"));
     decoder d(dv.decode());
     ASSERT(d.more());
-    try { get< ::int8_t>(d); FAIL("got bool as byte"); } catch(decode_error){}
+    try { get< ::int8_t>(d); FAIL("got bool as byte"); } catch(conversion_error){}
     ASSERT_EQUAL(true, get<bool>(d));
     ASSERT_EQUAL(false, get<bool>(d));
-    try { get< ::int8_t>(d); FAIL("got ubyte as byte"); } catch(decode_error){}
+    try { get< ::int8_t>(d); FAIL("got ubyte as byte"); } catch(conversion_error){}
     ASSERT_EQUAL(42, get< ::uint8_t>(d));
-    try { get< ::int32_t>(d); FAIL("got uint as ushort"); } catch(decode_error){}
+    try { get< ::int32_t>(d); FAIL("got uint as ushort"); } catch(conversion_error){}
     ASSERT_EQUAL(42, get< ::uint16_t>(d));
-    try { get< ::uint16_t>(d); FAIL("got short as ushort"); } catch(decode_error){}
+    try { get< ::uint16_t>(d); FAIL("got short as ushort"); } catch(conversion_error){}
     ASSERT_EQUAL(-42, get< ::int16_t>(d));
     ASSERT_EQUAL(12345, get< ::uint32_t>(d));
     ASSERT_EQUAL(-12345, get< ::int32_t>(d));
     ASSERT_EQUAL(12345, get< ::uint64_t>(d));
     ASSERT_EQUAL(-12345, get< ::int64_t>(d));
-    try { get<double>(d); FAIL("got float as double"); } catch(decode_error){}
+    try { get<double>(d); FAIL("got float as double"); } catch(conversion_error){}
     ASSERT_EQUAL(0.125, get<float>(d));
-    try { get<float>(d); FAIL("got double as float"); } catch(decode_error){}
+    try { get<float>(d); FAIL("got double as float"); } catch(conversion_error){}
     ASSERT_EQUAL(0.125, get<double>(d));
     ASSERT(!d.more());
 }
@@ -103,8 +103,8 @@ void test_value_conversions() {
     ASSERT_EQUAL(3, (v=amqp_byte(3)).get<long>());
     ASSERT_EQUAL(1.0, (v=amqp_float(1.0)).get<double>());
     ASSERT_EQUAL(1.0, (v=amqp_double(1.0)).get<float>());
-    try { (void)(v = amqp_byte(1)).get<bool>(); FAIL("got byte as bool"); } catch (decode_error) {}
-    try { (void)(v = true).get<float>(); FAIL("got bool as float"); } catch (decode_error) {}
+    try { (void)(v = amqp_byte(1)).get<bool>(); FAIL("got byte as bool"); } catch (conversion_error) {}
+    try { (void)(v = true).get<float>(); FAIL("got bool as float"); } catch (conversion_error) {}
 }
 
 // TODO aconway 2015-06-11: interop test is not complete.

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/8cbde662/proton-c/bindings/cpp/src/posix/io.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/posix/io.cpp b/proton-c/bindings/cpp/src/posix/io.cpp
index 6da2887..a85972a 100644
--- a/proton-c/bindings/cpp/src/posix/io.cpp
+++ b/proton-c/bindings/cpp/src/posix/io.cpp
@@ -48,12 +48,12 @@ std::string error_str() {
 namespace {
 
 template <class T> T check(T result, const std::string& msg=std::string()) {
-    if (result < 0) throw io_error(msg + error_str());
+    if (result < 0) throw connection_engine::io_error(msg + error_str());
     return result;
 }
 
 void gai_check(int result, const std::string& msg="") {
-    if (result) throw io_error(msg + gai_strerror(result));
+    if (result) throw connection_engine::io_error(msg + gai_strerror(result));
 }
 
 }

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/8cbde662/proton-c/bindings/cpp/src/scalar.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/scalar.cpp b/proton-c/bindings/cpp/src/scalar.cpp
index eab19e6..4306e6b 100644
--- a/proton-c/bindings/cpp/src/scalar.cpp
+++ b/proton-c/bindings/cpp/src/scalar.cpp
@@ -99,7 +99,7 @@ scalar& scalar::operator=(const std::string& x) { set(x, PN_STRING); return *thi
 scalar& scalar::operator=(const char* x) { set(x, PN_STRING); return *this; }
 
 void scalar::ok(pn_type_t t) const {
-    if (atom_.type != t) throw type_error(type_id(t), type());
+    if (atom_.type != t) throw make_conversion_error(type_id(t), type());
 }
 
 void scalar::get(bool& x) const { ok(PN_BOOL); x = atom_.u.as_bool; }
@@ -139,13 +139,13 @@ int64_t scalar::as_int() const {
       case PN_ULONG: return int64_t(atom_.u.as_ulong);
       case PN_LONG: return atom_.u.as_long;
       case PN_TIMESTAMP: return atom_.u.as_timestamp;
-      default: throw type_error(LONG, type(), "cannot convert");
+      default: throw make_conversion_error(LONG, type());
     }
 }
 
 uint64_t scalar::as_uint() const {
     if  (!type_id_is_integral(type()))
-        throw type_error(ULONG, type(), "cannot convert");
+        throw make_conversion_error(ULONG, type());
     return uint64_t(as_int());
 }
 
@@ -156,14 +156,14 @@ double scalar::as_double() const {
     switch (atom_.type) {
       case PN_DOUBLE: return atom_.u.as_double;
       case PN_FLOAT: return atom_.u.as_float;
-      default: throw type_error(DOUBLE, type(), "cannot convert");
+      default: throw make_conversion_error(DOUBLE, type());
     }
 }
 
 std::string scalar::as_string() const {
     if (type_id_is_string_like(type()))
         return str_;
-    throw type_error(STRING, type(), "cannot convert");
+    throw make_conversion_error(STRING, type());
 }
 
 namespace {

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/8cbde662/proton-c/bindings/cpp/src/scalar_test.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/scalar_test.cpp b/proton-c/bindings/cpp/src/scalar_test.cpp
index c444acd..2af58d0 100644
--- a/proton-c/bindings/cpp/src/scalar_test.cpp
+++ b/proton-c/bindings/cpp/src/scalar_test.cpp
@@ -53,13 +53,14 @@ template <class T> void type_test(T x, type_id tid, T y) {
     ASSERT(v2 > s);
 }
 
-#define ASSERT_MISMATCH(EXPR, WANT, GOT)                        \
-    try {                                                       \
-        (void)(EXPR);                                           \
-        FAIL("expected type_error: " #EXPR);                    \
-    } catch (const type_error& e) {                             \
-        ASSERT_EQUAL(WANT, e.want);                             \
-        ASSERT_EQUAL(GOT, e.got);                               \
+#define ASSERT_MISMATCH(EXPR, WANT, GOT)                                \
+    try {                                                               \
+        (void)(EXPR);                                                   \
+        FAIL("expected conversion_error: " #EXPR);                      \
+    } catch (const conversion_error& e) {                               \
+        std::ostringstream want;                                        \
+        want << "unexpected type, want: " << (WANT) << " got: " << (GOT); \
+        ASSERT_EQUAL(want.str(), std::string(e.what()));                \
     }
 
 void convert_test() {

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/8cbde662/proton-c/bindings/cpp/src/types.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/types.cpp b/proton-c/bindings/cpp/src/types.cpp
index 6f5b0d9..cc55531 100644
--- a/proton-c/bindings/cpp/src/types.cpp
+++ b/proton-c/bindings/cpp/src/types.cpp
@@ -26,20 +26,6 @@
 
 namespace proton {
 
-namespace {
-
-std::string mismatch_message(type_id want, type_id got, const std::string& msg=std::string()) {
-    std::ostringstream s;
-    s << "want " << want << " got " << got;
-    if (!msg.empty()) s << ": " << msg;
-    return s.str();
-}
-} // namespace
-
-type_error::type_error(type_id want_, type_id got_, const std::string &msg)
-    : decode_error(mismatch_message(want_, got_, msg)), want(want_), got(got_)
-{}
-
 std::string type_name(type_id t) {
     switch (t) {
       case NULL_TYPE: return "null";

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/8cbde662/proton-c/bindings/cpp/src/types_internal.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/types_internal.hpp b/proton-c/bindings/cpp/src/types_internal.hpp
index a77168d..a93913a 100644
--- a/proton-c/bindings/cpp/src/types_internal.hpp
+++ b/proton-c/bindings/cpp/src/types_internal.hpp
@@ -20,6 +20,8 @@
  */
 
 #include "proton/type_traits.hpp"
+#include "proton/error.hpp"
+#include <sstream>
 
 ///@file
 /// Internal helpers for encode/decode/type conversion.
@@ -33,6 +35,13 @@ typename enable_if<sizeof(T) == sizeof(U)>::type byte_copy(T &to, const U &from)
     std::copy(p, p + sizeof(T), reinterpret_cast<char*>(&to));
 }
 
+inline conversion_error
+make_conversion_error(type_id want, type_id got, const std::string& msg=std::string()) {
+    std::ostringstream s;
+    s << "unexpected type, want: " << want << " got: " << got;
+    if (!msg.empty()) s << ": " << msg;
+    return conversion_error(s.str());
+}
 
 }
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/8cbde662/proton-c/bindings/cpp/src/windows/io.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/windows/io.cpp b/proton-c/bindings/cpp/src/windows/io.cpp
index 1bdccef..52f5fc0 100644
--- a/proton-c/bindings/cpp/src/windows/io.cpp
+++ b/proton-c/bindings/cpp/src/windows/io.cpp
@@ -54,13 +54,13 @@ namespace {
 
 template <class T> T check(T result, const std::string& msg=std::string()) {
     if (result == SOCKET_ERROR)
-        throw io_error(msg + error_str());
+        throw connection_engine::io_error(msg + error_str());
     return result;
 }
 
 void gai_check(int result, const std::string& msg="") {
     if (result)
-        throw io_error(msg + gai_strerror(result));
+        throw connection_engine::io_error(msg + gai_strerror(result));
 }
 } // namespace
 
@@ -98,7 +98,7 @@ std::pair<size_t, bool> socket_engine::io_read(char *buf, size_t size) {
     if (n == 0) return std::make_pair(0, false);
     if (n == SOCKET_ERROR && WSAGetLastError() == WSAEWOULDBLOCK)
         return std::make_pair(0, true);
-    throw io_error("read: " + error_str());
+    throw connection_engine::io_error("read: " + error_str());
 }
 
 size_t socket_engine::io_write(const char *buf, size_t size) {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org