From e27e529e589ef89fbe010ebf7c5635ec2873f64f Mon Sep 17 00:00:00 2001 From: Determinant Date: Wed, 12 Jun 2019 19:14:40 -0400 Subject: WIP: error handling --- include/salticidae/netaddr.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'include/salticidae/netaddr.h') diff --git a/include/salticidae/netaddr.h b/include/salticidae/netaddr.h index 909e092..a25bf6f 100644 --- a/include/salticidae/netaddr.h +++ b/include/salticidae/netaddr.h @@ -53,7 +53,7 @@ struct NetAddr { void set_by_ip_port(const std::string &_addr, uint16_t _port) { struct hostent *h; if ((h = gethostbyname(_addr.c_str())) == nullptr) - throw SalticidaeError("gethostbyname failed"); + throw SalticidaeError(SALTI_ERROR_NETADDR_INVALID, errno); memmove(&ip, h->h_addr_list[0], sizeof(in_addr_t)); port = htons(_port); } @@ -61,19 +61,19 @@ struct NetAddr { NetAddr(const std::string &ip_port_addr) { size_t pos = ip_port_addr.find(":"); if (pos == std::string::npos) - throw SalticidaeError("invalid port format"); + throw SalticidaeError(SALTI_ERROR_NETADDR_INVALID); std::string ip_str = ip_port_addr.substr(0, pos); std::string port_str = ip_port_addr.substr(pos + 1); long port; try { port = std::stol(port_str.c_str()); } catch (std::logic_error &) { - throw SalticidaeError("invalid port format"); + throw SalticidaeError(SALTI_ERROR_NETADDR_INVALID); } if (port < 0) - throw SalticidaeError("negative port number"); + throw SalticidaeError(SALTI_ERROR_NETADDR_INVALID); if (port > 0xffff) - throw SalticidaeError("port number greater than 0xffff"); + throw SalticidaeError(SALTI_ERROR_NETADDR_INVALID); set_by_ip_port(ip_str, (uint16_t)port); } /* construct from unix socket format */ -- cgit v1.2.3