Skip to content

Commit 590d84a

Browse files
committed
fix: remove try-catch blocks to support exceptions-disabled builds
1 parent 4d3fde9 commit 590d84a

1 file changed

Lines changed: 4 additions & 8 deletions

File tree

src/cares_wrap.cc

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2179,10 +2179,8 @@ void GetServers(const FunctionCallbackInfo<Value>& args) {
21792179
if (bracket_end != std::string::npos) {
21802180
host = entry.substr(1, bracket_end - 1);
21812181
if (bracket_end + 1 < entry.size() && entry[bracket_end + 1] == ':') {
2182-
try {
2183-
port = std::stoi(entry.substr(bracket_end + 2));
2184-
} catch (...) { /* ignore */
2185-
}
2182+
int parsed = std::atoi(entry.substr(bracket_end + 2).c_str());
2183+
if (parsed > 0) port = parsed;
21862184
}
21872185
} else {
21882186
host = entry; // fallback if malformed
@@ -2195,10 +2193,8 @@ void GetServers(const FunctionCallbackInfo<Value>& args) {
21952193
auto first_colon = entry.find(':');
21962194
if (colon != std::string::npos && colon == first_colon) {
21972195
host = entry.substr(0, colon);
2198-
try {
2199-
port = std::stoi(entry.substr(colon + 1));
2200-
} catch (...) { /* ignore */
2201-
}
2196+
int parsed = std::atoi(entry.substr(colon + 1).c_str());
2197+
if (parsed > 0) port = parsed;
22022198
} else {
22032199
/* no port, or IPv6 addr without brackets */
22042200
host = entry;

0 commit comments

Comments
 (0)