Skip to content

Commit f0558c5

Browse files
author
abacus_fixer
committed
refactor(write_libxc_r): replace std::exception with WARNING_QUIT
Replace standard exception handling with project-specific error handling in write_libxc_r.cpp to comply with cpp-code-style skill guidelines. Changes: - Replace 9 instances of throw with ModuleBase::WARNING_QUIT - throw std::domain_error -> WARNING_QUIT - throw std::invalid_argument -> WARNING_QUIT - Remove #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 5682e00 commit f0558c5

1 file changed

Lines changed: 11 additions & 37 deletions

File tree

source/source_io/module_chgpot/write_libxc_r.cpp

Lines changed: 11 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
#include <xc.h>
2121
#include <iostream>
2222
#include <vector>
23-
#include <stdexcept>
2423
#include <unistd.h>
24+
#include "source_base/tool_quit.h"
2525

2626
void ModuleIO::write_libxc_r(
2727
const int order,
@@ -116,10 +116,7 @@ void ModuleIO::write_libxc_r(
116116
case 1: vrho .resize( nrxx * nspin );
117117
case 0: exc .resize( nrxx );
118118
break;
119-
default: throw std::domain_error(
120-
"order =" + std::to_string(order) +
121-
" unfinished in " + std::string(__FILE__) +
122-
" line " + std::to_string(__LINE__));
119+
default: ModuleBase::WARNING_QUIT("write_libxc_r", "order =" + std::to_string(order) + " not supported (must be 0-4)");
123120
break;
124121
}
125122
if(is_gga)
@@ -137,10 +134,7 @@ void ModuleIO::write_libxc_r(
137134
v2sigma2 .resize( nrxx * ((1==nspin)?1:6) );
138135
case 1: vsigma .resize( nrxx * ((1==nspin)?1:3) );
139136
case 0: break;
140-
default: throw std::domain_error(
141-
"order =" + std::to_string(order) +
142-
" unfinished in " + std::string(__FILE__) +
143-
" line " + std::to_string(__LINE__));
137+
default: ModuleBase::WARNING_QUIT("write_libxc_r", "order =" + std::to_string(order) + " not supported for GGA (must be 0-4)");
144138
break;
145139
}
146140
}
@@ -173,11 +167,8 @@ void ModuleIO::write_libxc_r(
173167
break;
174168
case 0: xc_lda_exc ( &func, nrxx, rho.data(), exc.data() );
175169
break;
176-
default: throw std::domain_error(
177-
"order =" + std::to_string(order) +
178-
" unfinished in " + std::string(__FILE__) +
179-
" line " + std::to_string(__LINE__));
180-
break;
170+
default: ModuleBase::WARNING_QUIT("write_libxc_r", "order =" + std::to_string(order) + " not supported for LDA (must be 0-4)");
171+
break;
181172
}
182173
break;
183174
}
@@ -205,21 +196,14 @@ void ModuleIO::write_libxc_r(
205196
break;
206197
case 0: xc_gga_exc ( &func, nrxx, rho.data(), sigma.data(), exc.data() );
207198
break;
208-
default: throw std::domain_error(
209-
"order =" + std::to_string(order) +
210-
" unfinished in " + std::string(__FILE__) +
211-
" line " + std::to_string(__LINE__));
199+
default: ModuleBase::WARNING_QUIT("write_libxc_r", "order =" + std::to_string(order) + " not supported for GGA (must be 0-4)");
212200
break;
213201
}
214202
break;
215203
}
216204
default:
217-
{
218-
throw std::domain_error(
219-
"func.info->family =" + std::to_string(func.info->family) +
220-
" unfinished in " + std::string(__FILE__) +
221-
" line " + std::to_string(__LINE__));
222-
break;
205+
ModuleBase::WARNING_QUIT("write_libxc_r", "func.info->family =" + std::to_string(func.info->family) + " not supported");
206+
break;
223207
}
224208
} // end switch( func.info->family )
225209
} // end for( xc_func_type &func : funcs )
@@ -258,11 +242,7 @@ void ModuleIO::write_libxc_r(
258242
pw_rhod.nz);
259243
#else
260244
if(nspin!=1)
261-
{ throw std::invalid_argument(
262-
"nspin=" + std::to_string(nspin) +
263-
" is invalid for ModuleIO::write_cube_core without MPI. see " +
264-
std::string(__FILE__) + " line " +
265-
std::to_string(__LINE__));
245+
{ ModuleBase::WARNING_QUIT("write_libxc_r", "nspin=" + std::to_string(nspin) + " is invalid for ModuleIO::write_cube_core without MPI");
266246
}
267247
ModuleIO::write_cube_core(
268248
ofs,
@@ -294,10 +274,7 @@ void ModuleIO::write_libxc_r(
294274
case 1: write_data( "vrho" , vrho , nspin );
295275
case 0: write_data( "exc" , exc , 1 );
296276
break;
297-
default: throw std::domain_error(
298-
"order =" + std::to_string(order) +
299-
" unfinished in " + std::string(__FILE__) +
300-
" line " + std::to_string(__LINE__));
277+
default: ModuleBase::WARNING_QUIT("write_libxc_r", "order =" + std::to_string(order) + " not supported (must be 0-4)");
301278
break;
302279
}
303280
if(is_gga)
@@ -315,10 +292,7 @@ void ModuleIO::write_libxc_r(
315292
write_data( "v2sigma2" , v2sigma2 , (1==nspin)?1:6 );
316293
case 1: write_data( "vsigma" , vsigma , (1==nspin)?1:3 );
317294
case 0: break;
318-
default: throw std::domain_error(
319-
"order =" + std::to_string(order) +
320-
" unfinished in " + std::string(__FILE__) +
321-
" line " + std::to_string(__LINE__));
295+
default: ModuleBase::WARNING_QUIT("write_libxc_r", "order =" + std::to_string(order) + " not supported for GGA (must be 0-4)");
322296
break;
323297
}
324298
}

0 commit comments

Comments
 (0)