From 8694318c71ef0fd22a0b2494f45f59ded1dcdfc4 Mon Sep 17 00:00:00 2001 From: jon-chuang Date: Thu, 13 Apr 2023 13:14:15 +0800 Subject: [PATCH] try-catch --- examples/common.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/common.cpp b/examples/common.cpp index ede8d1ba7..25b95feb0 100644 --- a/examples/common.cpp +++ b/examples/common.cpp @@ -42,8 +42,10 @@ bool gpt_params_parse(int argc, char ** argv, gpt_params & params) { while (std::getline(cpuinfo, line)) { if (line.find("cpu cores") != std::string::npos) { line.erase(0, line.find(": ") + 2); - params.n_threads = std::stoul(line); - break; + try { + params.n_threads = std::stoul(line); + break; + } catch (std::invalid_argument& e) {} // Ignore if we could not parse } } #elif defined(__APPLE__) && defined(__MACH__)