Skip to content

Commit 5682e00

Browse files
author
abacus_fixer
committed
refactor(restart): replace std::runtime_error with WARNING_QUIT
Replace standard exception handling with project-specific error handling in restart.cpp to comply with cpp-code-style skill guidelines. Changes: - Replace 4 instances of 'throw std::runtime_error' with ModuleBase::WARNING_QUIT in functions: write_file2() and read_file2() - Remove unnecessary #include <stdexcept> - Add #include "source_base/tool_quit.h" This follows the ABACUS code style rule that requires using ModuleBase::WARNING/WARNING_QUIT instead of standard exceptions.
1 parent 4f52aaf commit 5682e00

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

source/source_io/module_restart/restart.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
#include <unistd.h>
55

66
#include <fstream>
7-
#include <stdexcept>
87

98
#include "source_base/global_function.h"
9+
#include "source_base/tool_quit.h"
1010

1111
void Restart::write_file1(const std::string &file_name, const void*const ptr, const size_t size) const
1212
{
@@ -25,15 +25,15 @@ bool Restart::write_file2(const std::string& file_name, const void* const ptr, c
2525
const int file = open(file_name.c_str(), O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR);
2626
if (-1 == file){
2727
if (error_quit){
28-
throw std::runtime_error("can't open restart save file. \nerrno=" + ModuleBase::GlobalFunc::TO_STRING(errno) + ".\n" + std::string(__FILE__) + " line " + std::to_string(__LINE__));
28+
ModuleBase::WARNING_QUIT("Restart::write_file2", "can't open restart save file. errno=" + ModuleBase::GlobalFunc::TO_STRING(errno));
2929
} else {
3030
return false;
3131
}
3232
}
3333
auto error = write(file, ptr, size);
3434
if (-1 == error) {
3535
if (error_quit) {
36-
throw std::runtime_error("can't write restart save file. \nerrno=" + ModuleBase::GlobalFunc::TO_STRING(errno) + ".\n" + std::string(__FILE__) + " line " + std::to_string(__LINE__));
36+
ModuleBase::WARNING_QUIT("Restart::write_file2", "can't write restart save file. errno=" + ModuleBase::GlobalFunc::TO_STRING(errno));
3737
} else {
3838
return false;
3939
}
@@ -52,19 +52,19 @@ bool Restart::read_file2(const std::string& file_name, void* const ptr, const si
5252
const int file = open(file_name.c_str(), O_RDONLY);
5353
if (-1 == file) {
5454
if (error_quit) {
55-
throw std::runtime_error("can't open restart load file. \nerrno=" + ModuleBase::GlobalFunc::TO_STRING(errno) + ".\n" + std::string(__FILE__) + " line " + std::to_string(__LINE__));
55+
ModuleBase::WARNING_QUIT("Restart::read_file2", "can't open restart load file. errno=" + ModuleBase::GlobalFunc::TO_STRING(errno));
5656
} else {
5757
return false;
5858
}
5959
}
6060
auto error = read(file, ptr, size);
6161
if (-1 == error) {
6262
if (error_quit) {
63-
throw std::runtime_error("can't read restart load file. \nerrno=" + ModuleBase::GlobalFunc::TO_STRING(errno) + ".\n" + std::string(__FILE__) + " line " + std::to_string(__LINE__));
63+
ModuleBase::WARNING_QUIT("Restart::read_file2", "can't read restart load file. errno=" + ModuleBase::GlobalFunc::TO_STRING(errno));
6464
} else {
6565
return false;
6666
}
6767
}
6868
close(file);
6969
return true;
70-
}
70+
}

0 commit comments

Comments
 (0)