diff options
author | Charles E. Rolke <chug@apache.org> | 2013-09-30 22:20:34 +0000 |
---|---|---|
committer | Charles E. Rolke <chug@apache.org> | 2013-09-30 22:20:34 +0000 |
commit | afee22cecbae0aaf10fca24874c0f1af8df139ed (patch) | |
tree | e00632364a1a7bd711293d4d3443f7cce213085b /qpid/cpp/examples/messaging/hello_world.cpp | |
parent | 492e5662134f0f96b83bcbcfb8ff9609fb22a7a4 (diff) | |
download | qpid-python-afee22cecbae0aaf10fca24874c0f1af8df139ed.tar.gz |
QPID-5196: Messaging example hello_world core dumps when given a bad connection option
Move connection constructor into try-catch block
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1527802 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/cpp/examples/messaging/hello_world.cpp')
-rw-r--r-- | qpid/cpp/examples/messaging/hello_world.cpp | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/qpid/cpp/examples/messaging/hello_world.cpp b/qpid/cpp/examples/messaging/hello_world.cpp index 86342b3c47..a868a64b5e 100644 --- a/qpid/cpp/examples/messaging/hello_world.cpp +++ b/qpid/cpp/examples/messaging/hello_world.cpp @@ -33,9 +33,9 @@ int main(int argc, char** argv) { std::string broker = argc > 1 ? argv[1] : "localhost:5672"; std::string address = argc > 2 ? argv[2] : "amq.topic"; std::string connectionOptions = argc > 3 ? argv[3] : ""; - - Connection connection(broker, connectionOptions); + try { + Connection connection(broker, connectionOptions); connection.open(); Session session = connection.createSession(); @@ -47,12 +47,11 @@ int main(int argc, char** argv) { Message message = receiver.fetch(Duration::SECOND * 1); std::cout << message.getContent() << std::endl; session.acknowledge(); - + connection.close(); return 0; } catch(const std::exception& error) { std::cerr << error.what() << std::endl; - connection.close(); - return 1; + return 1; } } |