44#include < unistd.h>
55
66#include < fstream>
7+ #include < stdexcept>
78
89#include " source_base/global_function.h"
9- #include " source_base/tool_quit.h"
1010
1111void 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- ModuleBase::WARNING_QUIT ( " Restart::write_file2 " , " can't open restart save file. errno =" + ModuleBase::GlobalFunc::TO_STRING (errno));
28+ throw std::runtime_error ( " can't open restart save file. \n errno =" + ModuleBase::GlobalFunc::TO_STRING (errno) + " . \n " + std::string (__FILE__) + " line " + std::to_string (__LINE__ ));
2929 } else {
3030 return false ;
3131 }
3232 }
3333 auto error = write (file, ptr, size);
3434 if (-1 == error) {
3535 if (error_quit) {
36- ModuleBase::WARNING_QUIT ( " Restart::write_file2 " , " can't write restart save file. errno =" + ModuleBase::GlobalFunc::TO_STRING (errno));
36+ throw std::runtime_error ( " can't write restart save file. \n errno =" + ModuleBase::GlobalFunc::TO_STRING (errno) + " . \n " + std::string (__FILE__) + " line " + std::to_string (__LINE__ ));
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- ModuleBase::WARNING_QUIT ( " Restart::read_file2 " , " can't open restart load file. errno =" + ModuleBase::GlobalFunc::TO_STRING (errno));
55+ throw std::runtime_error ( " can't open restart load file. \n errno =" + ModuleBase::GlobalFunc::TO_STRING (errno) + " . \n " + std::string (__FILE__) + " line " + std::to_string (__LINE__ ));
5656 } else {
5757 return false ;
5858 }
5959 }
6060 auto error = read (file, ptr, size);
6161 if (-1 == error) {
6262 if (error_quit) {
63- ModuleBase::WARNING_QUIT ( " Restart::read_file2 " , " can't read restart load file. errno =" + ModuleBase::GlobalFunc::TO_STRING (errno));
63+ throw std::runtime_error ( " can't read restart load file. \n errno =" + ModuleBase::GlobalFunc::TO_STRING (errno) + " . \n " + std::string (__FILE__) + " line " + std::to_string (__LINE__ ));
6464 } else {
6565 return false ;
6666 }
6767 }
6868 close (file);
6969 return true ;
70- }
70+ }
0 commit comments