Skip to content

Commit 39c4f54

Browse files
Update source/source_cell/read_pp_upf201.cpp
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 0ede783 commit 39c4f54

1 file changed

Lines changed: 26 additions & 16 deletions

File tree

source/source_cell/read_pp_upf201.cpp

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -199,38 +199,48 @@ namespace // Helper functions for subsequent type conversion
199199
{
200200
int parse_int(const std::string& s)
201201
{
202+
size_t pos = 0;
203+
int value = 0;
202204
try
203205
{
204-
size_t pos = 0;
205-
int value = std::stoi(s, &pos);
206-
if (pos != s.size())
207-
{
208-
throw std::runtime_error("extra characters");
209-
}
210-
return value;
206+
value = std::stoi(s, &pos);
211207
}
212208
catch (...)
213209
{
214-
throw std::runtime_error("Invalid integer value: " + s);
210+
ModuleBase::WARNING_QUIT("read_pp_upf201::parse_int",
211+
"Invalid integer value: " + s);
215212
}
213+
214+
if (pos != s.size())
215+
{
216+
ModuleBase::WARNING_QUIT("read_pp_upf201::parse_int",
217+
"Invalid integer value (extra characters): " + s);
218+
}
219+
220+
return value;
216221
}
217222

218223
double parse_double(const std::string& s)
219224
{
225+
size_t pos = 0;
226+
double value = 0.0;
220227
try
221228
{
222-
size_t pos = 0;
223-
double value = std::stod(s, &pos);
224-
if (pos != s.size())
225-
{
226-
throw std::runtime_error("extra characters");
227-
}
228-
return value;
229+
value = std::stod(s, &pos);
229230
}
230231
catch (...)
231232
{
232-
throw std::runtime_error("Invalid floating-point value: " + s);
233+
ModuleBase::WARNING_QUIT("read_pp_upf201::parse_double",
234+
"Invalid floating-point value: " + s);
233235
}
236+
237+
if (pos != s.size())
238+
{
239+
ModuleBase::WARNING_QUIT("read_pp_upf201::parse_double",
240+
"Invalid floating-point value (extra characters): " + s);
241+
}
242+
243+
return value;
234244
}
235245
}
236246

0 commit comments

Comments
 (0)