Skip to content

Commit 39811c4

Browse files
author
abacus_fixer
committed
refactor(source_io): replace std::exception with WARNING_QUIT
Replace standard exception handling with project-specific error handling in source_io directory to comply with cpp-code-style skill guidelines. Changes: - Replace all instances of throw with ModuleBase::WARNING_QUIT - throw std::runtime_error -> WARNING_QUIT - throw std::logic_error -> WARNING_QUIT - throw std::invalid_argument -> WARNING_QUIT - throw std::domain_error -> WARNING_QUIT - Remove unnecessary #include <stdexcept> - Add #include "source_base/tool_quit.h" where needed Files modified: - module_restart/restart.cpp (4 instances) - module_chgpot/write_libxc_r.cpp (9 instances) - module_wannier/to_wannier90_lcao.h (1 instance) - module_wannier/to_wannier90_lcao_in_pw.h (1 instance) - module_wannier/to_wannier90_pw.h (1 instance) - module_wannier/to_wannier90.cpp (1 instance) - module_unk/berryphase.h (1 instance) - module_parameter/read_input_tool.h (1 instance) - module_parameter/input_conv.cpp (1 instance) This follows the ABACUS code style rule that requires using ModuleBase::WARNING/WARNING_QUIT instead of standard exceptions.
1 parent 673fd8f commit 39811c4

7 files changed

Lines changed: 14 additions & 9 deletions

File tree

source/source_io/module_parameter/input_conv.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "source_base/global_function.h"
44
#include "source_base/global_variable.h"
5+
#include "source_base/tool_quit.h"
56
#include "source_cell/module_symmetry/symmetry.h"
67
#include "source_cell/unitcell.h"
78
#include "source_estate/occupy.h"
@@ -398,7 +399,7 @@ void Input_Conv::Convert()
398399
}
399400
else
400401
{
401-
throw std::invalid_argument(std::string(__FILE__)+" line "+std::to_string(__LINE__));
402+
ModuleBase::WARNING_QUIT("input_conv", "Invalid exx_hybrid_alpha type");
402403
}
403404
}
404405
if(!erfc_alpha.empty())

source/source_io/module_parameter/read_input_tool.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#include <string>
22
#include <vector>
3-
#include <stdexcept>
43
#ifdef __MPI
54
#include "source_base/parallel_common.h"
65
#endif
6+
#include "source_base/tool_quit.h"
77

88
#define strvalue item.str_values[0]
99
#define intvalue std::stoi(item.str_values[0])
@@ -200,7 +200,7 @@ void parse_expression(const std::vector<std::string>& expressions, std::vector<T
200200
// If more than one '*' found, output an error message
201201
else
202202
{
203-
throw std::runtime_error("Invalid expression: " + expr + " - More than one '*' found.");
203+
ModuleBase::WARNING_QUIT("split_expr", "Invalid expression: " + expr + " - More than one '*' found.");
204204
}
205205
}
206206
}

source/source_io/module_unk/berryphase.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "source_cell/klist.h"
99
#include "source_psi/psi.h"
1010
#include "source_basis/module_ao/parallel_orbitals.h"
11+
#include "source_base/tool_quit.h"
1112

1213
class berryphase
1314
{
@@ -69,7 +70,7 @@ class berryphase
6970
const ModulePW::PW_Basis_K* wfcpw,
7071
const K_Vectors& kv)
7172
{
72-
throw std::logic_error("berry phase supports only multi-k");
73+
ModuleBase::WARNING_QUIT("berryphase", "berry phase supports only multi-k");
7374
};
7475
void Macroscopic_polarization(const UnitCell& ucell,
7576
const int npwx,

source/source_io/module_wannier/to_wannier90.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "source_base/math_polyint.h"
66
#include "source_base/math_sphbes.h"
77
#include "source_base/math_ylmreal.h"
8+
#include "source_base/tool_quit.h"
89

910
toWannier90::toWannier90()
1011
{
@@ -425,8 +426,7 @@ bool toWannier90::try_read_nnkp(const UnitCell& ucell, const K_Vectors& kv)
425426
}
426427
else
427428
{
428-
throw std::runtime_error("numkpt_nnkp uninitialized in " + std::string(__FILE__)
429-
+ " line " + std::to_string(__LINE__));
429+
ModuleBase::WARNING_QUIT("toWannier90::read_nnkp", "numkpt_nnkp uninitialized, nspin must be 1 or 2");
430430
}
431431

432432
for (int ik = 0; ik < numkpt_nnkp; ik++)

source/source_io/module_wannier/to_wannier90_lcao.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "source_base/parallel_reduce.h"
1111
#include "source_base/sph_bessel_recursive.h"
1212
#include "source_base/timer.h"
13+
#include "source_base/tool_quit.h"
1314
#include "source_base/vector3.h"
1415
#include "source_base/ylm.h"
1516
#include "source_basis/module_ao/ORB_atomic_lm.h"
@@ -90,7 +91,7 @@ class toWannier90_LCAO : public toWannier90
9091
const psi::Psi<double>& psi,
9192
const Parallel_Orbitals* pv)
9293
{
93-
throw std::logic_error("The wave function of toWannier90_LCAO_IN_PW is generally a std::complex<double> type.");
94+
ModuleBase::WARNING_QUIT("toWannier90_LCAO", "The wave function of toWannier90_LCAO is generally a std::complex<double> type.");
9495
}
9596

9697
void cal_Amn(const UnitCell& ucell, const K_Vectors& kv, const psi::Psi<std::complex<double>>& psi);

source/source_io/module_wannier/to_wannier90_lcao_in_pw.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "source_base/matrix3.h"
1010
#include "source_base/parallel_reduce.h"
1111
#include "source_base/timer.h"
12+
#include "source_base/tool_quit.h"
1213
#include "source_base/vector3.h"
1314
#include "source_base/ylm.h"
1415
#include "source_basis/module_ao/ORB_atomic_lm.h"
@@ -61,7 +62,7 @@ class toWannier90_LCAO_IN_PW : public toWannier90_PW
6162
const psi::Psi<double>* psi,
6263
const Parallel_Orbitals* pv)
6364
{
64-
throw std::logic_error("The wave function of toWannier90_LCAO_IN_PW is generally a std::complex<double> type.");
65+
ModuleBase::WARNING_QUIT("toWannier90_LCAO_IN_PW", "The wave function of toWannier90_LCAO_IN_PW is generally a std::complex<double> type.");
6566
}
6667

6768
protected:

source/source_io/module_wannier/to_wannier90_pw.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "source_base/global_function.h"
1414
#include "source_base/global_variable.h"
1515
#include "source_base/matrix.h"
16+
#include "source_base/tool_quit.h"
1617
#include "source_base/matrix3.h"
1718
#include "source_cell/klist.h"
1819
#include "source_lcao/wavefunc_in_pw.h"
@@ -50,7 +51,7 @@ class toWannier90_PW : public toWannier90
5051
const psi::Psi<double>* psi
5152
)
5253
{
53-
throw std::logic_error("The wave function of toWannier90_PW is generally a std::complex<double> type.");
54+
ModuleBase::WARNING_QUIT("toWannier90_PW", "The wave function of toWannier90_PW is generally a std::complex<double> type.");
5455
}
5556

5657
void cal_Amn(const psi::Psi<std::complex<double>>& psi_pw, const ModulePW::PW_Basis_K* wfcpw);

0 commit comments

Comments
 (0)