summaryrefslogtreecommitdiff
path: root/qpid/cpp/examples/messaging/hello_world.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'qpid/cpp/examples/messaging/hello_world.cpp')
-rw-r--r--qpid/cpp/examples/messaging/hello_world.cpp9
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;
}
}