summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorKjell Ahlstedt <kjellahlstedt@gmail.com>2020-12-09 15:40:54 +0100
committerKjell Ahlstedt <kjellahlstedt@gmail.com>2020-12-09 15:40:54 +0100
commit5a3d08fc1f306449a06d75bf330790d947812ee1 (patch)
treec47729121ca09dd3425a4d4e1a036927092cc1c0 /tests
parent12b5837128ab022a26f324e3476ccc7ede51e9b5 (diff)
downloadglibmm-5a3d08fc1f306449a06d75bf330790d947812ee1.tar.gz
tests/glibmm_tls_client: Catch exceptions from more function calls
Gio::Socket::create() can throw an exception. Put it in a try block. See #84
Diffstat (limited to 'tests')
-rw-r--r--tests/giomm_tls_client/main.cc24
1 files changed, 18 insertions, 6 deletions
diff --git a/tests/giomm_tls_client/main.cc b/tests/giomm_tls_client/main.cc
index 703de755..9ec2ea3c 100644
--- a/tests/giomm_tls_client/main.cc
+++ b/tests/giomm_tls_client/main.cc
@@ -76,19 +76,31 @@ main(int, char**)
std::cout << "First address of test host is " << first_inet_address->to_string() << "."
<< std::endl;
- auto socket = Gio::Socket::create(
- first_inet_address->get_family(), Gio::Socket::Type::STREAM, Gio::Socket::Protocol::TCP);
-
- auto address = Gio::InetSocketAddress::create(first_inet_address, 443);
+ Glib::RefPtr<Gio::Socket> socket;
+ try
+ {
+ socket = Gio::Socket::create(
+ first_inet_address->get_family(), Gio::Socket::Type::STREAM, Gio::Socket::Protocol::TCP);
+ }
+ catch (const Gio::Error& ex)
+ {
+ std::cout << "Could not create socket. Exception: " << ex.what() << std::endl;
+ return EXIT_FAILURE;
+ }
+ Glib::RefPtr<Gio::InetSocketAddress> address;
try
{
+ address = Gio::InetSocketAddress::create(first_inet_address, 443);
socket->connect(address);
}
catch (const Gio::Error& ex)
{
- std::cout << "Could not connect socket to " << address->get_address()->to_string() << ":"
- << address->get_port() << ". Exception: " << ex.what() << std::endl;
+ if (!address)
+ std::cout << "Could not create socket address. Exception: " << ex.what() << std::endl;
+ else
+ std::cout << "Could not connect socket to " << address->get_address()->to_string() << ":"
+ << address->get_port() << ". Exception: " << ex.what() << std::endl;
return EXIT_FAILURE;
}